From 215fe6dd19204c0e1f61472150a7cffd4bfbf7f8 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 6 Oct 2021 22:53:11 +0000 Subject: [PATCH 1/2] feat: add context manager support in client chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: https://github.com/googleapis/googleapis/commit/787f8c9a731f44e74a90b9847d48659ca9462d10 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9 --- 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 + owl-bot-staging/v1/docs/index.rst | 7 + .../v1/docs/vision_v1/image_annotator.rst | 6 + .../v1/docs/vision_v1/product_search.rst | 10 + .../v1/docs/vision_v1/services.rst | 7 + owl-bot-staging/v1/docs/vision_v1/types.rst | 7 + .../v1/google/cloud/vision/__init__.py | 195 + .../v1/google/cloud/vision/py.typed | 2 + .../v1/google/cloud/vision_v1/__init__.py | 196 + .../cloud/vision_v1/gapic_metadata.json | 267 + .../v1/google/cloud/vision_v1/py.typed | 2 + .../cloud/vision_v1/services/__init__.py | 15 + .../services/image_annotator/__init__.py | 22 + .../services/image_annotator/async_client.py | 525 ++ .../services/image_annotator/client.py | 703 ++ .../image_annotator/transports/__init__.py | 33 + .../image_annotator/transports/base.py | 255 + .../image_annotator/transports/grpc.py | 379 + .../transports/grpc_asyncio.py | 384 + .../services/product_search/__init__.py | 22 + .../services/product_search/async_client.py | 2104 ++++++ .../services/product_search/client.py | 2196 ++++++ .../services/product_search/pagers.py | 506 ++ .../product_search/transports/__init__.py | 33 + .../product_search/transports/base.py | 561 ++ .../product_search/transports/grpc.py | 912 +++ .../product_search/transports/grpc_asyncio.py | 917 +++ .../google/cloud/vision_v1/types/__init__.py | 198 + .../google/cloud/vision_v1/types/geometry.py | 125 + .../cloud/vision_v1/types/image_annotator.py | 1612 +++++ .../cloud/vision_v1/types/product_search.py | 222 + .../vision_v1/types/product_search_service.py | 1075 +++ .../cloud/vision_v1/types/text_annotation.py | 393 + .../cloud/vision_v1/types/web_detection.py | 201 + owl-bot-staging/v1/mypy.ini | 3 + owl-bot-staging/v1/noxfile.py | 132 + .../v1/scripts/fixup_vision_v1_keywords.py | 198 + owl-bot-staging/v1/setup.py | 54 + owl-bot-staging/v1/tests/__init__.py | 16 + owl-bot-staging/v1/tests/unit/__init__.py | 16 + .../v1/tests/unit/gapic/__init__.py | 16 + .../v1/tests/unit/gapic/vision_v1/__init__.py | 16 + .../gapic/vision_v1/test_image_annotator.py | 1723 +++++ .../gapic/vision_v1/test_product_search.py | 6323 +++++++++++++++++ owl-bot-staging/v1p1beta1/.coveragerc | 17 + owl-bot-staging/v1p1beta1/MANIFEST.in | 2 + owl-bot-staging/v1p1beta1/README.rst | 49 + owl-bot-staging/v1p1beta1/docs/conf.py | 376 + owl-bot-staging/v1p1beta1/docs/index.rst | 7 + .../docs/vision_v1p1beta1/image_annotator.rst | 6 + .../docs/vision_v1p1beta1/services.rst | 6 + .../v1p1beta1/docs/vision_v1p1beta1/types.rst | 7 + .../v1p1beta1/google/cloud/vision/__init__.py | 89 + .../v1p1beta1/google/cloud/vision/py.typed | 2 + .../google/cloud/vision_v1p1beta1/__init__.py | 90 + .../vision_v1p1beta1/gapic_metadata.json | 33 + .../google/cloud/vision_v1p1beta1/py.typed | 2 + .../vision_v1p1beta1/services/__init__.py | 15 + .../services/image_annotator/__init__.py | 22 + .../services/image_annotator/async_client.py | 241 + .../services/image_annotator/client.py | 422 ++ .../image_annotator/transports/__init__.py | 33 + .../image_annotator/transports/base.py | 185 + .../image_annotator/transports/grpc.py | 258 + .../transports/grpc_asyncio.py | 263 + .../cloud/vision_v1p1beta1/types/__init__.py | 92 + .../cloud/vision_v1p1beta1/types/geometry.py | 95 + .../vision_v1p1beta1/types/image_annotator.py | 947 +++ .../vision_v1p1beta1/types/text_annotation.py | 378 + .../vision_v1p1beta1/types/web_detection.py | 199 + owl-bot-staging/v1p1beta1/mypy.ini | 3 + owl-bot-staging/v1p1beta1/noxfile.py | 132 + .../fixup_vision_v1p1beta1_keywords.py | 176 + owl-bot-staging/v1p1beta1/setup.py | 54 + owl-bot-staging/v1p1beta1/tests/__init__.py | 16 + .../v1p1beta1/tests/unit/__init__.py | 16 + .../v1p1beta1/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/vision_v1p1beta1/__init__.py | 16 + .../vision_v1p1beta1/test_image_annotator.py | 1131 +++ owl-bot-staging/v1p2beta1/.coveragerc | 17 + owl-bot-staging/v1p2beta1/MANIFEST.in | 2 + owl-bot-staging/v1p2beta1/README.rst | 49 + owl-bot-staging/v1p2beta1/docs/conf.py | 376 + owl-bot-staging/v1p2beta1/docs/index.rst | 7 + .../docs/vision_v1p2beta1/image_annotator.rst | 6 + .../docs/vision_v1p2beta1/services.rst | 6 + .../v1p2beta1/docs/vision_v1p2beta1/types.rst | 7 + .../v1p2beta1/google/cloud/vision/__init__.py | 113 + .../v1p2beta1/google/cloud/vision/py.typed | 2 + .../google/cloud/vision_v1p2beta1/__init__.py | 114 + .../vision_v1p2beta1/gapic_metadata.json | 43 + .../google/cloud/vision_v1p2beta1/py.typed | 2 + .../vision_v1p2beta1/services/__init__.py | 15 + .../services/image_annotator/__init__.py | 22 + .../services/image_annotator/async_client.py | 334 + .../services/image_annotator/client.py | 508 ++ .../image_annotator/transports/__init__.py | 33 + .../image_annotator/transports/base.py | 213 + .../image_annotator/transports/grpc.py | 309 + .../transports/grpc_asyncio.py | 314 + .../cloud/vision_v1p2beta1/types/__init__.py | 116 + .../cloud/vision_v1p2beta1/types/geometry.py | 125 + .../vision_v1p2beta1/types/image_annotator.py | 1256 ++++ .../vision_v1p2beta1/types/text_annotation.py | 393 + .../vision_v1p2beta1/types/web_detection.py | 199 + owl-bot-staging/v1p2beta1/mypy.ini | 3 + owl-bot-staging/v1p2beta1/noxfile.py | 132 + .../fixup_vision_v1p2beta1_keywords.py | 177 + owl-bot-staging/v1p2beta1/setup.py | 54 + owl-bot-staging/v1p2beta1/tests/__init__.py | 16 + .../v1p2beta1/tests/unit/__init__.py | 16 + .../v1p2beta1/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/vision_v1p2beta1/__init__.py | 16 + .../vision_v1p2beta1/test_image_annotator.py | 1341 ++++ owl-bot-staging/v1p3beta1/.coveragerc | 17 + owl-bot-staging/v1p3beta1/MANIFEST.in | 2 + owl-bot-staging/v1p3beta1/README.rst | 49 + owl-bot-staging/v1p3beta1/docs/conf.py | 376 + owl-bot-staging/v1p3beta1/docs/index.rst | 7 + .../docs/vision_v1p3beta1/image_annotator.rst | 6 + .../docs/vision_v1p3beta1/product_search.rst | 10 + .../docs/vision_v1p3beta1/services.rst | 7 + .../v1p3beta1/docs/vision_v1p3beta1/types.rst | 7 + .../v1p3beta1/google/cloud/vision/__init__.py | 187 + .../v1p3beta1/google/cloud/vision/py.typed | 2 + .../google/cloud/vision_v1p3beta1/__init__.py | 188 + .../vision_v1p3beta1/gapic_metadata.json | 237 + .../google/cloud/vision_v1p3beta1/py.typed | 2 + .../vision_v1p3beta1/services/__init__.py | 15 + .../services/image_annotator/__init__.py | 22 + .../services/image_annotator/async_client.py | 336 + .../services/image_annotator/client.py | 530 ++ .../image_annotator/transports/__init__.py | 33 + .../image_annotator/transports/base.py | 211 + .../image_annotator/transports/grpc.py | 309 + .../transports/grpc_asyncio.py | 314 + .../services/product_search/__init__.py | 22 + .../services/product_search/async_client.py | 1988 ++++++ .../services/product_search/client.py | 2093 ++++++ .../services/product_search/pagers.py | 506 ++ .../product_search/transports/__init__.py | 33 + .../product_search/transports/base.py | 534 ++ .../product_search/transports/grpc.py | 880 +++ .../product_search/transports/grpc_asyncio.py | 885 +++ .../cloud/vision_v1p3beta1/types/__init__.py | 190 + .../cloud/vision_v1p3beta1/types/geometry.py | 141 + .../vision_v1p3beta1/types/image_annotator.py | 1327 ++++ .../vision_v1p3beta1/types/product_search.py | 249 + .../types/product_search_service.py | 998 +++ .../vision_v1p3beta1/types/text_annotation.py | 393 + .../vision_v1p3beta1/types/web_detection.py | 199 + owl-bot-staging/v1p3beta1/mypy.ini | 3 + owl-bot-staging/v1p3beta1/noxfile.py | 132 + .../fixup_vision_v1p3beta1_keywords.py | 195 + owl-bot-staging/v1p3beta1/setup.py | 54 + owl-bot-staging/v1p3beta1/tests/__init__.py | 16 + .../v1p3beta1/tests/unit/__init__.py | 16 + .../v1p3beta1/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/vision_v1p3beta1/__init__.py | 16 + .../vision_v1p3beta1/test_image_annotator.py | 1385 ++++ .../vision_v1p3beta1/test_product_search.py | 6093 ++++++++++++++++ owl-bot-staging/v1p4beta1/.coveragerc | 17 + owl-bot-staging/v1p4beta1/MANIFEST.in | 2 + owl-bot-staging/v1p4beta1/README.rst | 49 + owl-bot-staging/v1p4beta1/docs/conf.py | 376 + owl-bot-staging/v1p4beta1/docs/index.rst | 7 + .../docs/vision_v1p4beta1/image_annotator.rst | 6 + .../docs/vision_v1p4beta1/product_search.rst | 10 + .../docs/vision_v1p4beta1/services.rst | 7 + .../v1p4beta1/docs/vision_v1p4beta1/types.rst | 7 + .../v1p4beta1/google/cloud/vision/__init__.py | 201 + .../v1p4beta1/google/cloud/vision/py.typed | 2 + .../google/cloud/vision_v1p4beta1/__init__.py | 202 + .../vision_v1p4beta1/gapic_metadata.json | 267 + .../google/cloud/vision_v1p4beta1/py.typed | 2 + .../vision_v1p4beta1/services/__init__.py | 15 + .../services/image_annotator/__init__.py | 22 + .../services/image_annotator/async_client.py | 517 ++ .../services/image_annotator/client.py | 703 ++ .../image_annotator/transports/__init__.py | 33 + .../image_annotator/transports/base.py | 247 + .../image_annotator/transports/grpc.py | 379 + .../transports/grpc_asyncio.py | 384 + .../services/product_search/__init__.py | 22 + .../services/product_search/async_client.py | 2095 ++++++ .../services/product_search/client.py | 2200 ++++++ .../services/product_search/pagers.py | 506 ++ .../product_search/transports/__init__.py | 33 + .../product_search/transports/base.py | 548 ++ .../product_search/transports/grpc.py | 914 +++ .../product_search/transports/grpc_asyncio.py | 919 +++ .../cloud/vision_v1p4beta1/types/__init__.py | 206 + .../cloud/vision_v1p4beta1/types/face.py | 97 + .../cloud/vision_v1p4beta1/types/geometry.py | 125 + .../vision_v1p4beta1/types/image_annotator.py | 1518 ++++ .../vision_v1p4beta1/types/product_search.py | 222 + .../types/product_search_service.py | 1077 +++ .../vision_v1p4beta1/types/text_annotation.py | 393 + .../vision_v1p4beta1/types/web_detection.py | 201 + owl-bot-staging/v1p4beta1/mypy.ini | 3 + owl-bot-staging/v1p4beta1/noxfile.py | 132 + .../fixup_vision_v1p4beta1_keywords.py | 198 + owl-bot-staging/v1p4beta1/setup.py | 54 + owl-bot-staging/v1p4beta1/tests/__init__.py | 16 + .../v1p4beta1/tests/unit/__init__.py | 16 + .../v1p4beta1/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/vision_v1p4beta1/__init__.py | 16 + .../vision_v1p4beta1/test_image_annotator.py | 1724 +++++ .../vision_v1p4beta1/test_product_search.py | 6323 +++++++++++++++++ 212 files changed, 79041 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/index.rst create mode 100644 owl-bot-staging/v1/docs/vision_v1/image_annotator.rst create mode 100644 owl-bot-staging/v1/docs/vision_v1/product_search.rst create mode 100644 owl-bot-staging/v1/docs/vision_v1/services.rst create mode 100644 owl-bot-staging/v1/docs/vision_v1/types.rst create mode 100644 owl-bot-staging/v1/google/cloud/vision/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision/py.typed create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/py.typed create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py create mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.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_vision_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/vision_v1/__init__.py create mode 100644 owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_image_annotator.py create mode 100644 owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py create mode 100644 owl-bot-staging/v1p1beta1/.coveragerc create mode 100644 owl-bot-staging/v1p1beta1/MANIFEST.in create mode 100644 owl-bot-staging/v1p1beta1/README.rst create mode 100644 owl-bot-staging/v1p1beta1/docs/conf.py create mode 100644 owl-bot-staging/v1p1beta1/docs/index.rst create mode 100644 owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst create mode 100644 owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst create mode 100644 owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py create mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py create mode 100644 owl-bot-staging/v1p1beta1/mypy.ini create mode 100644 owl-bot-staging/v1p1beta1/noxfile.py create mode 100644 owl-bot-staging/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py create mode 100644 owl-bot-staging/v1p1beta1/setup.py create mode 100644 owl-bot-staging/v1p1beta1/tests/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__init__.py create mode 100644 owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py create mode 100644 owl-bot-staging/v1p2beta1/.coveragerc create mode 100644 owl-bot-staging/v1p2beta1/MANIFEST.in create mode 100644 owl-bot-staging/v1p2beta1/README.rst create mode 100644 owl-bot-staging/v1p2beta1/docs/conf.py create mode 100644 owl-bot-staging/v1p2beta1/docs/index.rst create mode 100644 owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst create mode 100644 owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst create mode 100644 owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/gapic_metadata.json create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py create mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py create mode 100644 owl-bot-staging/v1p2beta1/mypy.ini create mode 100644 owl-bot-staging/v1p2beta1/noxfile.py create mode 100644 owl-bot-staging/v1p2beta1/scripts/fixup_vision_v1p2beta1_keywords.py create mode 100644 owl-bot-staging/v1p2beta1/setup.py create mode 100644 owl-bot-staging/v1p2beta1/tests/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__init__.py create mode 100644 owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py create mode 100644 owl-bot-staging/v1p3beta1/.coveragerc create mode 100644 owl-bot-staging/v1p3beta1/MANIFEST.in create mode 100644 owl-bot-staging/v1p3beta1/README.rst create mode 100644 owl-bot-staging/v1p3beta1/docs/conf.py create mode 100644 owl-bot-staging/v1p3beta1/docs/index.rst create mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst create mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst create mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst create mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py create mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py create mode 100644 owl-bot-staging/v1p3beta1/mypy.ini create mode 100644 owl-bot-staging/v1p3beta1/noxfile.py create mode 100644 owl-bot-staging/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py create mode 100644 owl-bot-staging/v1p3beta1/setup.py create mode 100644 owl-bot-staging/v1p3beta1/tests/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__init__.py create mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py create mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py create mode 100644 owl-bot-staging/v1p4beta1/.coveragerc create mode 100644 owl-bot-staging/v1p4beta1/MANIFEST.in create mode 100644 owl-bot-staging/v1p4beta1/README.rst create mode 100644 owl-bot-staging/v1p4beta1/docs/conf.py create mode 100644 owl-bot-staging/v1p4beta1/docs/index.rst create mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst create mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst create mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst create mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py create mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py create mode 100644 owl-bot-staging/v1p4beta1/mypy.ini create mode 100644 owl-bot-staging/v1p4beta1/noxfile.py create mode 100644 owl-bot-staging/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py create mode 100644 owl-bot-staging/v1p4beta1/setup.py create mode 100644 owl-bot-staging/v1p4beta1/tests/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__init__.py create mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py create mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py diff --git a/owl-bot-staging/v1/.coveragerc b/owl-bot-staging/v1/.coveragerc new file mode 100644 index 00000000..75747063 --- /dev/null +++ b/owl-bot-staging/v1/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/vision/__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..67aa21f9 --- /dev/null +++ b/owl-bot-staging/v1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/vision *.py +recursive-include google/cloud/vision_v1 *.py diff --git a/owl-bot-staging/v1/README.rst b/owl-bot-staging/v1/README.rst new file mode 100644 index 00000000..39f9ca72 --- /dev/null +++ b/owl-bot-staging/v1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Vision 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 Vision 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..6e730bf5 --- /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-vision 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-vision" +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-vision-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-vision.tex", + u"google-cloud-vision 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-vision", + u"Google Cloud Vision 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-vision", + u"google-cloud-vision Documentation", + author, + "google-cloud-vision", + "GAPIC library for Google Cloud Vision 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/index.rst b/owl-bot-staging/v1/docs/index.rst new file mode 100644 index 00000000..84760df1 --- /dev/null +++ b/owl-bot-staging/v1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + vision_v1/services + vision_v1/types diff --git a/owl-bot-staging/v1/docs/vision_v1/image_annotator.rst b/owl-bot-staging/v1/docs/vision_v1/image_annotator.rst new file mode 100644 index 00000000..83130a76 --- /dev/null +++ b/owl-bot-staging/v1/docs/vision_v1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1.services.image_annotator + :members: + :inherited-members: diff --git a/owl-bot-staging/v1/docs/vision_v1/product_search.rst b/owl-bot-staging/v1/docs/vision_v1/product_search.rst new file mode 100644 index 00000000..96f1c798 --- /dev/null +++ b/owl-bot-staging/v1/docs/vision_v1/product_search.rst @@ -0,0 +1,10 @@ +ProductSearch +------------------------------- + +.. automodule:: google.cloud.vision_v1.services.product_search + :members: + :inherited-members: + +.. automodule:: google.cloud.vision_v1.services.product_search.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/v1/docs/vision_v1/services.rst b/owl-bot-staging/v1/docs/vision_v1/services.rst new file mode 100644 index 00000000..5fe11bc5 --- /dev/null +++ b/owl-bot-staging/v1/docs/vision_v1/services.rst @@ -0,0 +1,7 @@ +Services for Google Cloud Vision v1 API +======================================= +.. toctree:: + :maxdepth: 2 + + image_annotator + product_search diff --git a/owl-bot-staging/v1/docs/vision_v1/types.rst b/owl-bot-staging/v1/docs/vision_v1/types.rst new file mode 100644 index 00000000..52d9869b --- /dev/null +++ b/owl-bot-staging/v1/docs/vision_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Vision v1 API +==================================== + +.. automodule:: google.cloud.vision_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1/google/cloud/vision/__init__.py b/owl-bot-staging/v1/google/cloud/vision/__init__.py new file mode 100644 index 00000000..8d08cd2c --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision/__init__.py @@ -0,0 +1,195 @@ +# -*- 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.vision_v1.services.image_annotator.client import ImageAnnotatorClient +from google.cloud.vision_v1.services.image_annotator.async_client import ImageAnnotatorAsyncClient +from google.cloud.vision_v1.services.product_search.client import ProductSearchClient +from google.cloud.vision_v1.services.product_search.async_client import ProductSearchAsyncClient + +from google.cloud.vision_v1.types.geometry import BoundingPoly +from google.cloud.vision_v1.types.geometry import NormalizedVertex +from google.cloud.vision_v1.types.geometry import Position +from google.cloud.vision_v1.types.geometry import Vertex +from google.cloud.vision_v1.types.image_annotator import AnnotateFileRequest +from google.cloud.vision_v1.types.image_annotator import AnnotateFileResponse +from google.cloud.vision_v1.types.image_annotator import AnnotateImageRequest +from google.cloud.vision_v1.types.image_annotator import AnnotateImageResponse +from google.cloud.vision_v1.types.image_annotator import AsyncAnnotateFileRequest +from google.cloud.vision_v1.types.image_annotator import AsyncAnnotateFileResponse +from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateFilesRequest +from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateFilesResponse +from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateImagesRequest +from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateImagesResponse +from google.cloud.vision_v1.types.image_annotator import BatchAnnotateFilesRequest +from google.cloud.vision_v1.types.image_annotator import BatchAnnotateFilesResponse +from google.cloud.vision_v1.types.image_annotator import BatchAnnotateImagesRequest +from google.cloud.vision_v1.types.image_annotator import BatchAnnotateImagesResponse +from google.cloud.vision_v1.types.image_annotator import ColorInfo +from google.cloud.vision_v1.types.image_annotator import CropHint +from google.cloud.vision_v1.types.image_annotator import CropHintsAnnotation +from google.cloud.vision_v1.types.image_annotator import CropHintsParams +from google.cloud.vision_v1.types.image_annotator import DominantColorsAnnotation +from google.cloud.vision_v1.types.image_annotator import EntityAnnotation +from google.cloud.vision_v1.types.image_annotator import FaceAnnotation +from google.cloud.vision_v1.types.image_annotator import Feature +from google.cloud.vision_v1.types.image_annotator import GcsDestination +from google.cloud.vision_v1.types.image_annotator import GcsSource +from google.cloud.vision_v1.types.image_annotator import Image +from google.cloud.vision_v1.types.image_annotator import ImageAnnotationContext +from google.cloud.vision_v1.types.image_annotator import ImageContext +from google.cloud.vision_v1.types.image_annotator import ImageProperties +from google.cloud.vision_v1.types.image_annotator import ImageSource +from google.cloud.vision_v1.types.image_annotator import InputConfig +from google.cloud.vision_v1.types.image_annotator import LatLongRect +from google.cloud.vision_v1.types.image_annotator import LocalizedObjectAnnotation +from google.cloud.vision_v1.types.image_annotator import LocationInfo +from google.cloud.vision_v1.types.image_annotator import OperationMetadata +from google.cloud.vision_v1.types.image_annotator import OutputConfig +from google.cloud.vision_v1.types.image_annotator import Property +from google.cloud.vision_v1.types.image_annotator import SafeSearchAnnotation +from google.cloud.vision_v1.types.image_annotator import TextDetectionParams +from google.cloud.vision_v1.types.image_annotator import WebDetectionParams +from google.cloud.vision_v1.types.image_annotator import Likelihood +from google.cloud.vision_v1.types.product_search import ProductSearchParams +from google.cloud.vision_v1.types.product_search import ProductSearchResults +from google.cloud.vision_v1.types.product_search_service import AddProductToProductSetRequest +from google.cloud.vision_v1.types.product_search_service import BatchOperationMetadata +from google.cloud.vision_v1.types.product_search_service import CreateProductRequest +from google.cloud.vision_v1.types.product_search_service import CreateProductSetRequest +from google.cloud.vision_v1.types.product_search_service import CreateReferenceImageRequest +from google.cloud.vision_v1.types.product_search_service import DeleteProductRequest +from google.cloud.vision_v1.types.product_search_service import DeleteProductSetRequest +from google.cloud.vision_v1.types.product_search_service import DeleteReferenceImageRequest +from google.cloud.vision_v1.types.product_search_service import GetProductRequest +from google.cloud.vision_v1.types.product_search_service import GetProductSetRequest +from google.cloud.vision_v1.types.product_search_service import GetReferenceImageRequest +from google.cloud.vision_v1.types.product_search_service import ImportProductSetsGcsSource +from google.cloud.vision_v1.types.product_search_service import ImportProductSetsInputConfig +from google.cloud.vision_v1.types.product_search_service import ImportProductSetsRequest +from google.cloud.vision_v1.types.product_search_service import ImportProductSetsResponse +from google.cloud.vision_v1.types.product_search_service import ListProductSetsRequest +from google.cloud.vision_v1.types.product_search_service import ListProductSetsResponse +from google.cloud.vision_v1.types.product_search_service import ListProductsInProductSetRequest +from google.cloud.vision_v1.types.product_search_service import ListProductsInProductSetResponse +from google.cloud.vision_v1.types.product_search_service import ListProductsRequest +from google.cloud.vision_v1.types.product_search_service import ListProductsResponse +from google.cloud.vision_v1.types.product_search_service import ListReferenceImagesRequest +from google.cloud.vision_v1.types.product_search_service import ListReferenceImagesResponse +from google.cloud.vision_v1.types.product_search_service import Product +from google.cloud.vision_v1.types.product_search_service import ProductSet +from google.cloud.vision_v1.types.product_search_service import ProductSetPurgeConfig +from google.cloud.vision_v1.types.product_search_service import PurgeProductsRequest +from google.cloud.vision_v1.types.product_search_service import ReferenceImage +from google.cloud.vision_v1.types.product_search_service import RemoveProductFromProductSetRequest +from google.cloud.vision_v1.types.product_search_service import UpdateProductRequest +from google.cloud.vision_v1.types.product_search_service import UpdateProductSetRequest +from google.cloud.vision_v1.types.text_annotation import Block +from google.cloud.vision_v1.types.text_annotation import Page +from google.cloud.vision_v1.types.text_annotation import Paragraph +from google.cloud.vision_v1.types.text_annotation import Symbol +from google.cloud.vision_v1.types.text_annotation import TextAnnotation +from google.cloud.vision_v1.types.text_annotation import Word +from google.cloud.vision_v1.types.web_detection import WebDetection + +__all__ = ('ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', + 'ProductSearchClient', + 'ProductSearchAsyncClient', + 'BoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileRequest', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'AsyncBatchAnnotateImagesRequest', + 'AsyncBatchAnnotateImagesResponse', + 'BatchAnnotateFilesRequest', + 'BatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocalizedObjectAnnotation', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'ProductSearchParams', + 'ProductSearchResults', + 'AddProductToProductSetRequest', + 'BatchOperationMetadata', + 'CreateProductRequest', + 'CreateProductSetRequest', + 'CreateReferenceImageRequest', + 'DeleteProductRequest', + 'DeleteProductSetRequest', + 'DeleteReferenceImageRequest', + 'GetProductRequest', + 'GetProductSetRequest', + 'GetReferenceImageRequest', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ListProductsRequest', + 'ListProductsResponse', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'Product', + 'ProductSet', + 'ProductSetPurgeConfig', + 'PurgeProductsRequest', + 'ReferenceImage', + 'RemoveProductFromProductSetRequest', + 'UpdateProductRequest', + 'UpdateProductSetRequest', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1/google/cloud/vision/py.typed b/owl-bot-staging/v1/google/cloud/vision/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/__init__.py new file mode 100644 index 00000000..21daa9df --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/__init__.py @@ -0,0 +1,196 @@ +# -*- 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.image_annotator import ImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient +from .services.product_search import ProductSearchClient +from .services.product_search import ProductSearchAsyncClient + +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Position +from .types.geometry import Vertex +from .types.image_annotator import AnnotateFileRequest +from .types.image_annotator import AnnotateFileResponse +from .types.image_annotator import AnnotateImageRequest +from .types.image_annotator import AnnotateImageResponse +from .types.image_annotator import AsyncAnnotateFileRequest +from .types.image_annotator import AsyncAnnotateFileResponse +from .types.image_annotator import AsyncBatchAnnotateFilesRequest +from .types.image_annotator import AsyncBatchAnnotateFilesResponse +from .types.image_annotator import AsyncBatchAnnotateImagesRequest +from .types.image_annotator import AsyncBatchAnnotateImagesResponse +from .types.image_annotator import BatchAnnotateFilesRequest +from .types.image_annotator import BatchAnnotateFilesResponse +from .types.image_annotator import BatchAnnotateImagesRequest +from .types.image_annotator import BatchAnnotateImagesResponse +from .types.image_annotator import ColorInfo +from .types.image_annotator import CropHint +from .types.image_annotator import CropHintsAnnotation +from .types.image_annotator import CropHintsParams +from .types.image_annotator import DominantColorsAnnotation +from .types.image_annotator import EntityAnnotation +from .types.image_annotator import FaceAnnotation +from .types.image_annotator import Feature +from .types.image_annotator import GcsDestination +from .types.image_annotator import GcsSource +from .types.image_annotator import Image +from .types.image_annotator import ImageAnnotationContext +from .types.image_annotator import ImageContext +from .types.image_annotator import ImageProperties +from .types.image_annotator import ImageSource +from .types.image_annotator import InputConfig +from .types.image_annotator import LatLongRect +from .types.image_annotator import LocalizedObjectAnnotation +from .types.image_annotator import LocationInfo +from .types.image_annotator import OperationMetadata +from .types.image_annotator import OutputConfig +from .types.image_annotator import Property +from .types.image_annotator import SafeSearchAnnotation +from .types.image_annotator import TextDetectionParams +from .types.image_annotator import WebDetectionParams +from .types.image_annotator import Likelihood +from .types.product_search import ProductSearchParams +from .types.product_search import ProductSearchResults +from .types.product_search_service import AddProductToProductSetRequest +from .types.product_search_service import BatchOperationMetadata +from .types.product_search_service import CreateProductRequest +from .types.product_search_service import CreateProductSetRequest +from .types.product_search_service import CreateReferenceImageRequest +from .types.product_search_service import DeleteProductRequest +from .types.product_search_service import DeleteProductSetRequest +from .types.product_search_service import DeleteReferenceImageRequest +from .types.product_search_service import GetProductRequest +from .types.product_search_service import GetProductSetRequest +from .types.product_search_service import GetReferenceImageRequest +from .types.product_search_service import ImportProductSetsGcsSource +from .types.product_search_service import ImportProductSetsInputConfig +from .types.product_search_service import ImportProductSetsRequest +from .types.product_search_service import ImportProductSetsResponse +from .types.product_search_service import ListProductSetsRequest +from .types.product_search_service import ListProductSetsResponse +from .types.product_search_service import ListProductsInProductSetRequest +from .types.product_search_service import ListProductsInProductSetResponse +from .types.product_search_service import ListProductsRequest +from .types.product_search_service import ListProductsResponse +from .types.product_search_service import ListReferenceImagesRequest +from .types.product_search_service import ListReferenceImagesResponse +from .types.product_search_service import Product +from .types.product_search_service import ProductSet +from .types.product_search_service import ProductSetPurgeConfig +from .types.product_search_service import PurgeProductsRequest +from .types.product_search_service import ReferenceImage +from .types.product_search_service import RemoveProductFromProductSetRequest +from .types.product_search_service import UpdateProductRequest +from .types.product_search_service import UpdateProductSetRequest +from .types.text_annotation import Block +from .types.text_annotation import Page +from .types.text_annotation import Paragraph +from .types.text_annotation import Symbol +from .types.text_annotation import TextAnnotation +from .types.text_annotation import Word +from .types.web_detection import WebDetection + +__all__ = ( + 'ImageAnnotatorAsyncClient', + 'ProductSearchAsyncClient', +'AddProductToProductSetRequest', +'AnnotateFileRequest', +'AnnotateFileResponse', +'AnnotateImageRequest', +'AnnotateImageResponse', +'AsyncAnnotateFileRequest', +'AsyncAnnotateFileResponse', +'AsyncBatchAnnotateFilesRequest', +'AsyncBatchAnnotateFilesResponse', +'AsyncBatchAnnotateImagesRequest', +'AsyncBatchAnnotateImagesResponse', +'BatchAnnotateFilesRequest', +'BatchAnnotateFilesResponse', +'BatchAnnotateImagesRequest', +'BatchAnnotateImagesResponse', +'BatchOperationMetadata', +'Block', +'BoundingPoly', +'ColorInfo', +'CreateProductRequest', +'CreateProductSetRequest', +'CreateReferenceImageRequest', +'CropHint', +'CropHintsAnnotation', +'CropHintsParams', +'DeleteProductRequest', +'DeleteProductSetRequest', +'DeleteReferenceImageRequest', +'DominantColorsAnnotation', +'EntityAnnotation', +'FaceAnnotation', +'Feature', +'GcsDestination', +'GcsSource', +'GetProductRequest', +'GetProductSetRequest', +'GetReferenceImageRequest', +'Image', +'ImageAnnotationContext', +'ImageAnnotatorClient', +'ImageContext', +'ImageProperties', +'ImageSource', +'ImportProductSetsGcsSource', +'ImportProductSetsInputConfig', +'ImportProductSetsRequest', +'ImportProductSetsResponse', +'InputConfig', +'LatLongRect', +'Likelihood', +'ListProductSetsRequest', +'ListProductSetsResponse', +'ListProductsInProductSetRequest', +'ListProductsInProductSetResponse', +'ListProductsRequest', +'ListProductsResponse', +'ListReferenceImagesRequest', +'ListReferenceImagesResponse', +'LocalizedObjectAnnotation', +'LocationInfo', +'NormalizedVertex', +'OperationMetadata', +'OutputConfig', +'Page', +'Paragraph', +'Position', +'Product', +'ProductSearchClient', +'ProductSearchParams', +'ProductSearchResults', +'ProductSet', +'ProductSetPurgeConfig', +'Property', +'PurgeProductsRequest', +'ReferenceImage', +'RemoveProductFromProductSetRequest', +'SafeSearchAnnotation', +'Symbol', +'TextAnnotation', +'TextDetectionParams', +'UpdateProductRequest', +'UpdateProductSetRequest', +'Vertex', +'WebDetection', +'WebDetectionParams', +'Word', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json b/owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json new file mode 100644 index 00000000..71b189b5 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json @@ -0,0 +1,267 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.vision_v1", + "protoPackage": "google.cloud.vision.v1", + "schema": "1.0", + "services": { + "ImageAnnotator": { + "clients": { + "grpc": { + "libraryClient": "ImageAnnotatorClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "AsyncBatchAnnotateImages": { + "methods": [ + "async_batch_annotate_images" + ] + }, + "BatchAnnotateFiles": { + "methods": [ + "batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ImageAnnotatorAsyncClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "AsyncBatchAnnotateImages": { + "methods": [ + "async_batch_annotate_images" + ] + }, + "BatchAnnotateFiles": { + "methods": [ + "batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + } + } + }, + "ProductSearch": { + "clients": { + "grpc": { + "libraryClient": "ProductSearchClient", + "rpcs": { + "AddProductToProductSet": { + "methods": [ + "add_product_to_product_set" + ] + }, + "CreateProduct": { + "methods": [ + "create_product" + ] + }, + "CreateProductSet": { + "methods": [ + "create_product_set" + ] + }, + "CreateReferenceImage": { + "methods": [ + "create_reference_image" + ] + }, + "DeleteProduct": { + "methods": [ + "delete_product" + ] + }, + "DeleteProductSet": { + "methods": [ + "delete_product_set" + ] + }, + "DeleteReferenceImage": { + "methods": [ + "delete_reference_image" + ] + }, + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "GetProductSet": { + "methods": [ + "get_product_set" + ] + }, + "GetReferenceImage": { + "methods": [ + "get_reference_image" + ] + }, + "ImportProductSets": { + "methods": [ + "import_product_sets" + ] + }, + "ListProductSets": { + "methods": [ + "list_product_sets" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + }, + "ListProductsInProductSet": { + "methods": [ + "list_products_in_product_set" + ] + }, + "ListReferenceImages": { + "methods": [ + "list_reference_images" + ] + }, + "PurgeProducts": { + "methods": [ + "purge_products" + ] + }, + "RemoveProductFromProductSet": { + "methods": [ + "remove_product_from_product_set" + ] + }, + "UpdateProduct": { + "methods": [ + "update_product" + ] + }, + "UpdateProductSet": { + "methods": [ + "update_product_set" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductSearchAsyncClient", + "rpcs": { + "AddProductToProductSet": { + "methods": [ + "add_product_to_product_set" + ] + }, + "CreateProduct": { + "methods": [ + "create_product" + ] + }, + "CreateProductSet": { + "methods": [ + "create_product_set" + ] + }, + "CreateReferenceImage": { + "methods": [ + "create_reference_image" + ] + }, + "DeleteProduct": { + "methods": [ + "delete_product" + ] + }, + "DeleteProductSet": { + "methods": [ + "delete_product_set" + ] + }, + "DeleteReferenceImage": { + "methods": [ + "delete_reference_image" + ] + }, + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "GetProductSet": { + "methods": [ + "get_product_set" + ] + }, + "GetReferenceImage": { + "methods": [ + "get_reference_image" + ] + }, + "ImportProductSets": { + "methods": [ + "import_product_sets" + ] + }, + "ListProductSets": { + "methods": [ + "list_product_sets" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + }, + "ListProductsInProductSet": { + "methods": [ + "list_products_in_product_set" + ] + }, + "ListReferenceImages": { + "methods": [ + "list_reference_images" + ] + }, + "PurgeProducts": { + "methods": [ + "purge_products" + ] + }, + "RemoveProductFromProductSet": { + "methods": [ + "remove_product_from_product_set" + ] + }, + "UpdateProduct": { + "methods": [ + "update_product" + ] + }, + "UpdateProductSet": { + "methods": [ + "update_product_set" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/py.typed b/owl-bot-staging/v1/google/cloud/vision_v1/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_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/vision_v1/services/image_annotator/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/__init__.py new file mode 100644 index 00000000..3cbfa2fa --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/__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 ImageAnnotatorClient +from .async_client import ImageAnnotatorAsyncClient + +__all__ = ( + 'ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py new file mode 100644 index 00000000..21891218 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py @@ -0,0 +1,525 @@ +# -*- 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.vision_v1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport +from .client import ImageAnnotatorClient + + +class ImageAnnotatorAsyncClient: + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + _client: ImageAnnotatorClient + + DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT + + product_path = staticmethod(ImageAnnotatorClient.product_path) + parse_product_path = staticmethod(ImageAnnotatorClient.parse_product_path) + product_set_path = staticmethod(ImageAnnotatorClient.product_set_path) + parse_product_set_path = staticmethod(ImageAnnotatorClient.parse_product_set_path) + common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) + parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) + common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) + parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) + common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) + parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) + common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) + parse_common_location_path = staticmethod(ImageAnnotatorClient.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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def batch_annotate_images(self, + request: image_annotator.BatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (:class:`google.cloud.vision_v1.types.BatchAnnotateImagesRequest`): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def batch_annotate_files(self, + request: image_annotator.BatchAnnotateFilesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateFilesResponse: + r"""Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Args: + request (:class:`google.cloud.vision_v1.types.BatchAnnotateFilesRequest`): + The request object. A list of requests to annotate files + using the BatchAnnotateFiles API. + requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]`): + Required. The list of file annotation + requests. Right now we support only one + AnnotateFileRequest in + BatchAnnotateFilesRequest. + + 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.cloud.vision_v1.types.BatchAnnotateFilesResponse: + A list of file annotation responses. + """ + # 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 = image_annotator.BatchAnnotateFilesRequest(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_annotate_files, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def async_batch_annotate_images(self, + request: image_annotator.AsyncBatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + output_config: image_annotator.OutputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Args: + request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest`): + The request object. Request for async image annotation + for a list of images. + requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): + Required. Individual image annotation + requests for this batch. + + This corresponds to the ``requests`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (:class:`google.cloud.vision_v1.types.OutputConfig`): + Required. The desired output location + and metadata (e.g. format). + + This corresponds to the ``output_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.vision_v1.types.AsyncBatchAnnotateImagesResponse` + Response to an async batch image annotation request. + + """ + # 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, output_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 = image_annotator.AsyncBatchAnnotateImagesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if output_config is not None: + request.output_config = output_config + 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.async_batch_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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, + image_annotator.AsyncBatchAnnotateImagesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + async def async_batch_annotate_files(self, + request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest`): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]`): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorAsyncClient", +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py new file mode 100644 index 00000000..17aa88a0 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py @@ -0,0 +1,703 @@ +# -*- 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 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.vision_v1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ImageAnnotatorGrpcTransport +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +class ImageAnnotatorClientMeta(type): + """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] + _transport_registry["grpc"] = ImageAnnotatorGrpcTransport + _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ImageAnnotatorTransport]: + """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + @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 = "vision.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: + ImageAnnotatorClient: 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: + ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(project: str,location: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_set_path(project: str,location: str,product_set: str,) -> str: + """Returns a fully-qualified product_set string.""" + return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + + @staticmethod + def parse_product_set_path(path: str) -> Dict[str,str]: + """Parses a product_set path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?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, ImageAnnotatorTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): + # transport is a ImageAnnotatorTransport 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, + always_use_jwt_access=True, + ) + + def batch_annotate_images(self, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (Union[google.cloud.vision_v1.types.BatchAnnotateImagesRequest, dict]): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 image_annotator.BatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): + request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def batch_annotate_files(self, + request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateFilesResponse: + r"""Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Args: + request (Union[google.cloud.vision_v1.types.BatchAnnotateFilesRequest, dict]): + The request object. A list of requests to annotate files + using the BatchAnnotateFiles API. + requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]): + Required. The list of file annotation + requests. Right now we support only one + AnnotateFileRequest in + BatchAnnotateFilesRequest. + + 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.cloud.vision_v1.types.BatchAnnotateFilesResponse: + A list of file annotation responses. + """ + # 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 image_annotator.BatchAnnotateFilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateFilesRequest): + request = image_annotator.BatchAnnotateFilesRequest(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_annotate_files] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def async_batch_annotate_images(self, + request: Union[image_annotator.AsyncBatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + output_config: image_annotator.OutputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Args: + request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest, dict]): + The request object. Request for async image annotation + for a list of images. + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + + This corresponds to the ``requests`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (google.cloud.vision_v1.types.OutputConfig): + Required. The desired output location + and metadata (e.g. format). + + This corresponds to the ``output_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.vision_v1.types.AsyncBatchAnnotateImagesResponse` + Response to an async batch image annotation request. + + """ + # 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, output_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 image_annotator.AsyncBatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.AsyncBatchAnnotateImagesRequest): + request = image_annotator.AsyncBatchAnnotateImagesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if requests is not None: + request.requests = requests + if output_config is not None: + request.output_config = output_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.async_batch_annotate_images] + + # 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, + image_annotator.AsyncBatchAnnotateImagesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + def async_batch_annotate_files(self, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest, dict]): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 image_annotator.AsyncBatchAnnotateFilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): + request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorClient", +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/__init__.py new file mode 100644 index 00000000..94f01250 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/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 ImageAnnotatorTransport +from .grpc import ImageAnnotatorGrpcTransport +from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] +_transport_registry['grpc'] = ImageAnnotatorGrpcTransport +_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport + +__all__ = ( + 'ImageAnnotatorTransport', + 'ImageAnnotatorGrpcTransport', + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py new file mode 100644 index 00000000..1f72a9a6 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py @@ -0,0 +1,255 @@ +# -*- 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.vision_v1.types import image_annotator +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-vision', + ).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 ImageAnnotatorTransport(abc.ABC): + """Abstract transport class for ImageAnnotator.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( + self.batch_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.batch_annotate_files: gapic_v1.method.wrap_method( + self.batch_annotate_files, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.async_batch_annotate_images: gapic_v1.method.wrap_method( + self.async_batch_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.async_batch_annotate_files: gapic_v1.method.wrap_method( + self.async_batch_annotate_files, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Union[ + image_annotator.BatchAnnotateImagesResponse, + Awaitable[image_annotator.BatchAnnotateImagesResponse] + ]]: + raise NotImplementedError() + + @property + def batch_annotate_files(self) -> Callable[ + [image_annotator.BatchAnnotateFilesRequest], + Union[ + image_annotator.BatchAnnotateFilesResponse, + Awaitable[image_annotator.BatchAnnotateFilesResponse] + ]]: + raise NotImplementedError() + + @property + def async_batch_annotate_images(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateImagesRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ImageAnnotatorTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py new file mode 100644 index 00000000..7dce19bd --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py @@ -0,0 +1,379 @@ +# -*- 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.vision_v1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO + + +class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): + """gRPC backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + image_annotator.BatchAnnotateImagesResponse]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + ~.BatchAnnotateImagesResponse]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def batch_annotate_files(self) -> Callable[ + [image_annotator.BatchAnnotateFilesRequest], + image_annotator.BatchAnnotateFilesResponse]: + r"""Return a callable for the batch annotate files method over gRPC. + + Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Returns: + Callable[[~.BatchAnnotateFilesRequest], + ~.BatchAnnotateFilesResponse]: + 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_annotate_files' not in self._stubs: + self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateFiles', + request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, + ) + return self._stubs['batch_annotate_files'] + + @property + def async_batch_annotate_images(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateImagesRequest], + operations_pb2.Operation]: + r"""Return a callable for the async batch annotate images method over gRPC. + + Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Returns: + Callable[[~.AsyncBatchAnnotateImagesRequest], + ~.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 'async_batch_annotate_images' not in self._stubs: + self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages', + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + operations_pb2.Operation]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + ~.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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ImageAnnotatorGrpcTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py new file mode 100644 index 00000000..809204b5 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py @@ -0,0 +1,384 @@ +# -*- 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.vision_v1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .grpc import ImageAnnotatorGrpcTransport + + +class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): + """gRPC AsyncIO backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Awaitable[image_annotator.BatchAnnotateImagesResponse]]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + Awaitable[~.BatchAnnotateImagesResponse]]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def batch_annotate_files(self) -> Callable[ + [image_annotator.BatchAnnotateFilesRequest], + Awaitable[image_annotator.BatchAnnotateFilesResponse]]: + r"""Return a callable for the batch annotate files method over gRPC. + + Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Returns: + Callable[[~.BatchAnnotateFilesRequest], + Awaitable[~.BatchAnnotateFilesResponse]]: + 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_annotate_files' not in self._stubs: + self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateFiles', + request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, + ) + return self._stubs['batch_annotate_files'] + + @property + def async_batch_annotate_images(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateImagesRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the async batch annotate images method over gRPC. + + Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Returns: + Callable[[~.AsyncBatchAnnotateImagesRequest], + 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 'async_batch_annotate_images' not in self._stubs: + self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages', + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + 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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__init__.py new file mode 100644 index 00000000..cf79a54d --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__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 ProductSearchClient +from .async_client import ProductSearchAsyncClient + +__all__ = ( + 'ProductSearchClient', + 'ProductSearchAsyncClient', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py new file mode 100644 index 00000000..c97fe0c5 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py @@ -0,0 +1,2104 @@ +# -*- 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.vision_v1.services.product_search import pagers +from google.cloud.vision_v1.types import geometry +from google.cloud.vision_v1.types import product_search_service +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport +from .client import ProductSearchClient + + +class ProductSearchAsyncClient: + """Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + """ + + _client: ProductSearchClient + + DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT + + product_path = staticmethod(ProductSearchClient.product_path) + parse_product_path = staticmethod(ProductSearchClient.parse_product_path) + product_set_path = staticmethod(ProductSearchClient.product_set_path) + parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) + reference_image_path = staticmethod(ProductSearchClient.reference_image_path) + parse_reference_image_path = staticmethod(ProductSearchClient.parse_reference_image_path) + common_billing_account_path = staticmethod(ProductSearchClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductSearchClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductSearchClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductSearchClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductSearchClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductSearchClient.parse_common_organization_path) + common_project_path = staticmethod(ProductSearchClient.common_project_path) + parse_common_project_path = staticmethod(ProductSearchClient.parse_common_project_path) + common_location_path = staticmethod(ProductSearchClient.common_location_path) + parse_common_location_path = staticmethod(ProductSearchClient.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: + ProductSearchAsyncClient: The constructed client. + """ + return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, 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: + ProductSearchAsyncClient: The constructed client. + """ + return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductSearchTransport: + """Returns the transport used by the client instance. + + Returns: + ProductSearchTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ProductSearchClient).get_transport_class, type(ProductSearchClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ProductSearchTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product search 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, ~.ProductSearchTransport]): 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 = ProductSearchClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def create_product_set(self, + request: product_search_service.CreateProductSetRequest = None, + *, + parent: str = None, + product_set: product_search_service.ProductSet = None, + product_set_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Args: + request (:class:`google.cloud.vision_v1.types.CreateProductSetRequest`): + The request object. Request message for the + `CreateProductSet` method. + parent (:class:`str`): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set (:class:`google.cloud.vision_v1.types.ProductSet`): + Required. The ProductSet to create. + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set_id (:class:`str`): + A user-supplied resource id for this ProductSet. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_set_id`` 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.vision_v1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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, product_set, product_set_id]) + 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 = product_search_service.CreateProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product_set is not None: + request.product_set = product_set + if product_set_id is not None: + request.product_set_id = product_set_id + + # 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_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def list_product_sets(self, + request: product_search_service.ListProductSetsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductSetsAsyncPager: + r"""Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1.types.ListProductSetsRequest`): + The request object. Request message for the + `ListProductSets` method. + parent (:class:`str`): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.vision_v1.services.product_search.pagers.ListProductSetsAsyncPager: + Response message for the ListProductSets method. + + 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 = product_search_service.ListProductSetsRequest(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_product_sets, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductSetsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_product_set(self, + request: product_search_service.GetProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (:class:`google.cloud.vision_v1.types.GetProductSetRequest`): + The request object. Request message for the + `GetProductSet` method. + name (:class:`str`): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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 = product_search_service.GetProductSetRequest(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.get_product_set, + 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=600.0, + ), + default_timeout=600.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 update_product_set(self, + request: product_search_service.UpdateProductSetRequest = None, + *, + product_set: product_search_service.ProductSet = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Args: + request (:class:`google.cloud.vision_v1.types.UpdateProductSetRequest`): + The request object. Request message for the + `UpdateProductSet` method. + product_set (:class:`google.cloud.vision_v1.types.ProductSet`): + Required. The ProductSet resource + which replaces the one on the server. + + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask path is ``display_name``. + + This corresponds to the ``update_mask`` 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.vision_v1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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([product_set, update_mask]) + 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 = product_search_service.UpdateProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_set is not None: + request.product_set = product_set + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_product_set, + 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=600.0, + ), + default_timeout=600.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(( + ("product_set.name", request.product_set.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product_set(self, + request: product_search_service.DeleteProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (:class:`google.cloud.vision_v1.types.DeleteProductSetRequest`): + The request object. Request message for the + `DeleteProductSet` method. + name (:class:`str`): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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. + """ + # 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 = product_search_service.DeleteProductSetRequest(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_product_set, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_product(self, + request: product_search_service.CreateProductRequest = None, + *, + parent: str = None, + product: product_search_service.Product = None, + product_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Args: + request (:class:`google.cloud.vision_v1.types.CreateProductRequest`): + The request object. Request message for the + `CreateProduct` method. + parent (:class:`str`): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`google.cloud.vision_v1.types.Product`): + Required. The product to create. + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_id (:class:`str`): + A user-supplied resource id for this Product. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_id`` 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.vision_v1.types.Product: + A Product contains ReferenceImages. + """ + # 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, product, product_id]) + 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 = product_search_service.CreateProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product is not None: + request.product = product + if product_id is not None: + request.product_id = product_id + + # 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_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def list_products(self, + request: product_search_service.ListProductsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsAsyncPager: + r"""Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1.types.ListProductsRequest`): + The request object. Request message for the + `ListProducts` method. + parent (:class:`str`): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + + 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.vision_v1.services.product_search.pagers.ListProductsAsyncPager: + Response message for the ListProducts method. + + 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 = product_search_service.ListProductsRequest(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_products, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_product(self, + request: product_search_service.GetProductRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Args: + request (:class:`google.cloud.vision_v1.types.GetProductRequest`): + The request object. Request message for the `GetProduct` + method. + name (:class:`str`): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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.vision_v1.types.Product: + A Product contains ReferenceImages. + """ + # 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 = product_search_service.GetProductRequest(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.get_product, + 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=600.0, + ), + default_timeout=600.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 update_product(self, + request: product_search_service.UpdateProductRequest = None, + *, + product: product_search_service.Product = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Args: + request (:class:`google.cloud.vision_v1.types.UpdateProductRequest`): + The request object. Request message for the + `UpdateProduct` method. + product (:class:`google.cloud.vision_v1.types.Product`): + Required. The Product resource which + replaces the one on the server. + product.name is immutable. + + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask paths include ``product_labels``, ``display_name``, + and ``description``. + + This corresponds to the ``update_mask`` 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.vision_v1.types.Product: + A Product contains ReferenceImages. + """ + # 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([product, update_mask]) + 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 = product_search_service.UpdateProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product is not None: + request.product = product + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_product, + 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=600.0, + ), + default_timeout=600.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(( + ("product.name", request.product.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product(self, + request: product_search_service.DeleteProductRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Args: + request (:class:`google.cloud.vision_v1.types.DeleteProductRequest`): + The request object. Request message for the + `DeleteProduct` method. + name (:class:`str`): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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. + """ + # 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 = product_search_service.DeleteProductRequest(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_product, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_reference_image(self, + request: product_search_service.CreateReferenceImageRequest = None, + *, + parent: str = None, + reference_image: product_search_service.ReferenceImage = None, + reference_image_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Args: + request (:class:`google.cloud.vision_v1.types.CreateReferenceImageRequest`): + The request object. Request message for the + `CreateReferenceImage` method. + parent (:class:`str`): + Required. Resource name of the product in which to + create the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image (:class:`google.cloud.vision_v1.types.ReferenceImage`): + Required. The reference image to + create. If an image ID is specified, it + is ignored. + + This corresponds to the ``reference_image`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image_id (:class:`str`): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value + as the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``reference_image_id`` 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.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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, reference_image, reference_image_id]) + 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 = product_search_service.CreateReferenceImageRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reference_image is not None: + request.reference_image = reference_image + if reference_image_id is not None: + request.reference_image_id = reference_image_id + + # 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_reference_image, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def delete_reference_image(self, + request: product_search_service.DeleteReferenceImageRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (:class:`google.cloud.vision_v1.types.DeleteReferenceImageRequest`): + The request object. Request message for the + `DeleteReferenceImage` method. + name (:class:`str`): + Required. The resource name of the reference image to + delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + + 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. + """ + # 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 = product_search_service.DeleteReferenceImageRequest(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_reference_image, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_reference_images(self, + request: product_search_service.ListReferenceImagesRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReferenceImagesAsyncPager: + r"""Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Args: + request (:class:`google.cloud.vision_v1.types.ListReferenceImagesRequest`): + The request object. Request message for the + `ListReferenceImages` method. + parent (:class:`str`): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + 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.vision_v1.services.product_search.pagers.ListReferenceImagesAsyncPager: + Response message for the ListReferenceImages method. + + 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 = product_search_service.ListReferenceImagesRequest(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_reference_images, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListReferenceImagesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_reference_image(self, + request: product_search_service.GetReferenceImageRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Args: + request (:class:`google.cloud.vision_v1.types.GetReferenceImageRequest`): + The request object. Request message for the + `GetReferenceImage` method. + name (:class:`str`): + Required. The resource name of the ReferenceImage to + get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + 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.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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 = product_search_service.GetReferenceImageRequest(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.get_reference_image, + 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=600.0, + ), + default_timeout=600.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 add_product_to_product_set(self, + request: product_search_service.AddProductToProductSetRequest = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Args: + request (:class:`google.cloud.vision_v1.types.AddProductToProductSetRequest`): + The request object. Request message for the + `AddProductToProductSet` method. + name (:class:`str`): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`str`): + Required. The resource name for the Product to be added + to this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 = product_search_service.AddProductToProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_product_to_product_set, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def remove_product_from_product_set(self, + request: product_search_service.RemoveProductFromProductSetRequest = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Removes a Product from the specified ProductSet. + + Args: + request (:class:`google.cloud.vision_v1.types.RemoveProductFromProductSetRequest`): + The request object. Request message for the + `RemoveProductFromProductSet` method. + name (:class:`str`): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`str`): + Required. The resource name for the Product to be + removed from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 = product_search_service.RemoveProductFromProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.remove_product_from_product_set, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_products_in_product_set(self, + request: product_search_service.ListProductsInProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsInProductSetAsyncPager: + r"""Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1.types.ListProductsInProductSetRequest`): + The request object. Request message for the + `ListProductsInProductSet` method. + name (:class:`str`): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1.services.product_search.pagers.ListProductsInProductSetAsyncPager: + Response message for the ListProductsInProductSet + method. + + 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([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 = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsInProductSetAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def import_product_sets(self, + request: product_search_service.ImportProductSetsRequest = None, + *, + parent: str = None, + input_config: product_search_service.ImportProductSetsInputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + + Args: + request (:class:`google.cloud.vision_v1.types.ImportProductSetsRequest`): + The request object. Request message for the + `ImportProductSets` method. + parent (:class:`str`): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_config (:class:`google.cloud.vision_v1.types.ImportProductSetsInputConfig`): + Required. The input content for the + list of requests. + + This corresponds to the ``input_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.vision_v1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + """ + # 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, input_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 = product_search_service.ImportProductSetsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if input_config is not None: + request.input_config = input_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.import_product_sets, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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, + product_search_service.ImportProductSetsResponse, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + async def purge_products(self, + request: product_search_service.PurgeProductsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Args: + request (:class:`google.cloud.vision_v1.types.PurgeProductsRequest`): + The request object. Request message for the + `PurgeProducts` method. + parent (:class:`str`): + Required. The project and location in which the Products + should be deleted. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.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([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 = product_search_service.PurgeProductsRequest(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.purge_products, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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, + empty_pb2.Empty, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ProductSearchAsyncClient", +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py new file mode 100644 index 00000000..4979db09 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py @@ -0,0 +1,2196 @@ +# -*- 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 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.vision_v1.services.product_search import pagers +from google.cloud.vision_v1.types import geometry +from google.cloud.vision_v1.types import product_search_service +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductSearchGrpcTransport +from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport + + +class ProductSearchClientMeta(type): + """Metaclass for the ProductSearch 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[ProductSearchTransport]] + _transport_registry["grpc"] = ProductSearchGrpcTransport + _transport_registry["grpc_asyncio"] = ProductSearchGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ProductSearchTransport]: + """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 ProductSearchClient(metaclass=ProductSearchClientMeta): + """Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + """ + + @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 = "vision.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: + ProductSearchClient: 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: + ProductSearchClient: 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) -> ProductSearchTransport: + """Returns the transport used by the client instance. + + Returns: + ProductSearchTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(project: str,location: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_set_path(project: str,location: str,product_set: str,) -> str: + """Returns a fully-qualified product_set string.""" + return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + + @staticmethod + def parse_product_set_path(path: str) -> Dict[str,str]: + """Parses a product_set path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def reference_image_path(project: str,location: str,product: str,reference_image: str,) -> str: + """Returns a fully-qualified reference_image string.""" + return "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) + + @staticmethod + def parse_reference_image_path(path: str) -> Dict[str,str]: + """Parses a reference_image path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)/referenceImages/(?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, ProductSearchTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product search 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, ProductSearchTransport]): 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, ProductSearchTransport): + # transport is a ProductSearchTransport 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, + always_use_jwt_access=True, + ) + + def create_product_set(self, + request: Union[product_search_service.CreateProductSetRequest, dict] = None, + *, + parent: str = None, + product_set: product_search_service.ProductSet = None, + product_set_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Args: + request (Union[google.cloud.vision_v1.types.CreateProductSetRequest, dict]): + The request object. Request message for the + `CreateProductSet` method. + parent (str): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set (google.cloud.vision_v1.types.ProductSet): + Required. The ProductSet to create. + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set_id (str): + A user-supplied resource id for this ProductSet. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_set_id`` 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.vision_v1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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, product_set, product_set_id]) + 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 product_search_service.CreateProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateProductSetRequest): + request = product_search_service.CreateProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product_set is not None: + request.product_set = product_set + if product_set_id is not None: + request.product_set_id = product_set_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_product_set] + + # 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_product_sets(self, + request: Union[product_search_service.ListProductSetsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductSetsPager: + r"""Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Args: + request (Union[google.cloud.vision_v1.types.ListProductSetsRequest, dict]): + The request object. Request message for the + `ListProductSets` method. + parent (str): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.vision_v1.services.product_search.pagers.ListProductSetsPager: + Response message for the ListProductSets method. + + 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 product_search_service.ListProductSetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductSetsRequest): + request = product_search_service.ListProductSetsRequest(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_product_sets] + + # 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.ListProductSetsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_product_set(self, + request: Union[product_search_service.GetProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (Union[google.cloud.vision_v1.types.GetProductSetRequest, dict]): + The request object. Request message for the + `GetProductSet` method. + name (str): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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 product_search_service.GetProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetProductSetRequest): + request = product_search_service.GetProductSetRequest(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.get_product_set] + + # 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 update_product_set(self, + request: Union[product_search_service.UpdateProductSetRequest, dict] = None, + *, + product_set: product_search_service.ProductSet = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Args: + request (Union[google.cloud.vision_v1.types.UpdateProductSetRequest, dict]): + The request object. Request message for the + `UpdateProductSet` method. + product_set (google.cloud.vision_v1.types.ProductSet): + Required. The ProductSet resource + which replaces the one on the server. + + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask path is ``display_name``. + + This corresponds to the ``update_mask`` 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.vision_v1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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([product_set, update_mask]) + 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 product_search_service.UpdateProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.UpdateProductSetRequest): + request = product_search_service.UpdateProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_set is not None: + request.product_set = product_set + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product_set] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product_set(self, + request: Union[product_search_service.DeleteProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (Union[google.cloud.vision_v1.types.DeleteProductSetRequest, dict]): + The request object. Request message for the + `DeleteProductSet` method. + name (str): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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. + """ + # 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 product_search_service.DeleteProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteProductSetRequest): + request = product_search_service.DeleteProductSetRequest(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_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_product(self, + request: Union[product_search_service.CreateProductRequest, dict] = None, + *, + parent: str = None, + product: product_search_service.Product = None, + product_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Args: + request (Union[google.cloud.vision_v1.types.CreateProductRequest, dict]): + The request object. Request message for the + `CreateProduct` method. + parent (str): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (google.cloud.vision_v1.types.Product): + Required. The product to create. + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_id (str): + A user-supplied resource id for this Product. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_id`` 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.vision_v1.types.Product: + A Product contains ReferenceImages. + """ + # 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, product, product_id]) + 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 product_search_service.CreateProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateProductRequest): + request = product_search_service.CreateProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product is not None: + request.product = product + if product_id is not None: + request.product_id = product_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_product] + + # 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_products(self, + request: Union[product_search_service.ListProductsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsPager: + r"""Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (Union[google.cloud.vision_v1.types.ListProductsRequest, dict]): + The request object. Request message for the + `ListProducts` method. + parent (str): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + + 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.vision_v1.services.product_search.pagers.ListProductsPager: + Response message for the ListProducts method. + + 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 product_search_service.ListProductsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductsRequest): + request = product_search_service.ListProductsRequest(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_products] + + # 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.ListProductsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_product(self, + request: Union[product_search_service.GetProductRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Args: + request (Union[google.cloud.vision_v1.types.GetProductRequest, dict]): + The request object. Request message for the `GetProduct` + method. + name (str): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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.vision_v1.types.Product: + A Product contains ReferenceImages. + """ + # 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 product_search_service.GetProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetProductRequest): + request = product_search_service.GetProductRequest(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.get_product] + + # 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 update_product(self, + request: Union[product_search_service.UpdateProductRequest, dict] = None, + *, + product: product_search_service.Product = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Args: + request (Union[google.cloud.vision_v1.types.UpdateProductRequest, dict]): + The request object. Request message for the + `UpdateProduct` method. + product (google.cloud.vision_v1.types.Product): + Required. The Product resource which + replaces the one on the server. + product.name is immutable. + + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask paths include ``product_labels``, ``display_name``, + and ``description``. + + This corresponds to the ``update_mask`` 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.vision_v1.types.Product: + A Product contains ReferenceImages. + """ + # 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([product, update_mask]) + 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 product_search_service.UpdateProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.UpdateProductRequest): + request = product_search_service.UpdateProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product is not None: + request.product = product + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product(self, + request: Union[product_search_service.DeleteProductRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Args: + request (Union[google.cloud.vision_v1.types.DeleteProductRequest, dict]): + The request object. Request message for the + `DeleteProduct` method. + name (str): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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. + """ + # 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 product_search_service.DeleteProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteProductRequest): + request = product_search_service.DeleteProductRequest(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_product] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_reference_image(self, + request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, + *, + parent: str = None, + reference_image: product_search_service.ReferenceImage = None, + reference_image_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Args: + request (Union[google.cloud.vision_v1.types.CreateReferenceImageRequest, dict]): + The request object. Request message for the + `CreateReferenceImage` method. + parent (str): + Required. Resource name of the product in which to + create the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image (google.cloud.vision_v1.types.ReferenceImage): + Required. The reference image to + create. If an image ID is specified, it + is ignored. + + This corresponds to the ``reference_image`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image_id (str): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value + as the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``reference_image_id`` 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.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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, reference_image, reference_image_id]) + 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 product_search_service.CreateReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateReferenceImageRequest): + request = product_search_service.CreateReferenceImageRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reference_image is not None: + request.reference_image = reference_image + if reference_image_id is not None: + request.reference_image_id = reference_image_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_reference_image] + + # 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_reference_image(self, + request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (Union[google.cloud.vision_v1.types.DeleteReferenceImageRequest, dict]): + The request object. Request message for the + `DeleteReferenceImage` method. + name (str): + Required. The resource name of the reference image to + delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + + 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. + """ + # 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 product_search_service.DeleteReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteReferenceImageRequest): + request = product_search_service.DeleteReferenceImageRequest(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_reference_image] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_reference_images(self, + request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReferenceImagesPager: + r"""Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Args: + request (Union[google.cloud.vision_v1.types.ListReferenceImagesRequest, dict]): + The request object. Request message for the + `ListReferenceImages` method. + parent (str): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + 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.vision_v1.services.product_search.pagers.ListReferenceImagesPager: + Response message for the ListReferenceImages method. + + 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 product_search_service.ListReferenceImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListReferenceImagesRequest): + request = product_search_service.ListReferenceImagesRequest(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_reference_images] + + # 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.ListReferenceImagesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_reference_image(self, + request: Union[product_search_service.GetReferenceImageRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Args: + request (Union[google.cloud.vision_v1.types.GetReferenceImageRequest, dict]): + The request object. Request message for the + `GetReferenceImage` method. + name (str): + Required. The resource name of the ReferenceImage to + get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + 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.vision_v1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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 product_search_service.GetReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetReferenceImageRequest): + request = product_search_service.GetReferenceImageRequest(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.get_reference_image] + + # 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 add_product_to_product_set(self, + request: Union[product_search_service.AddProductToProductSetRequest, dict] = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Args: + request (Union[google.cloud.vision_v1.types.AddProductToProductSetRequest, dict]): + The request object. Request message for the + `AddProductToProductSet` method. + name (str): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (str): + Required. The resource name for the Product to be added + to this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 product_search_service.AddProductToProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.AddProductToProductSetRequest): + request = product_search_service.AddProductToProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_product_to_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def remove_product_from_product_set(self, + request: Union[product_search_service.RemoveProductFromProductSetRequest, dict] = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Removes a Product from the specified ProductSet. + + Args: + request (Union[google.cloud.vision_v1.types.RemoveProductFromProductSetRequest, dict]): + The request object. Request message for the + `RemoveProductFromProductSet` method. + name (str): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (str): + Required. The resource name for the Product to be + removed from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 product_search_service.RemoveProductFromProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.RemoveProductFromProductSetRequest): + request = product_search_service.RemoveProductFromProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.remove_product_from_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_products_in_product_set(self, + request: Union[product_search_service.ListProductsInProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsInProductSetPager: + r"""Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (Union[google.cloud.vision_v1.types.ListProductsInProductSetRequest, dict]): + The request object. Request message for the + `ListProductsInProductSet` method. + name (str): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1.services.product_search.pagers.ListProductsInProductSetPager: + Response message for the ListProductsInProductSet + method. + + 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([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 product_search_service.ListProductsInProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductsInProductSetRequest): + request = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set] + + # 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListProductsInProductSetPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def import_product_sets(self, + request: Union[product_search_service.ImportProductSetsRequest, dict] = None, + *, + parent: str = None, + input_config: product_search_service.ImportProductSetsInputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + + Args: + request (Union[google.cloud.vision_v1.types.ImportProductSetsRequest, dict]): + The request object. Request message for the + `ImportProductSets` method. + parent (str): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_config (google.cloud.vision_v1.types.ImportProductSetsInputConfig): + Required. The input content for the + list of requests. + + This corresponds to the ``input_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.vision_v1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + """ + # 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, input_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 product_search_service.ImportProductSetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ImportProductSetsRequest): + request = product_search_service.ImportProductSetsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if input_config is not None: + request.input_config = input_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.import_product_sets] + + # 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, + product_search_service.ImportProductSetsResponse, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + def purge_products(self, + request: Union[product_search_service.PurgeProductsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Args: + request (Union[google.cloud.vision_v1.types.PurgeProductsRequest, dict]): + The request object. Request message for the + `PurgeProducts` method. + parent (str): + Required. The project and location in which the Products + should be deleted. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.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([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 product_search_service.PurgeProductsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.PurgeProductsRequest): + request = product_search_service.PurgeProductsRequest(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.purge_products] + + # 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, + empty_pb2.Empty, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ProductSearchClient", +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py new file mode 100644 index 00000000..6ae241ca --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py @@ -0,0 +1,506 @@ +# -*- 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, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator + +from google.cloud.vision_v1.types import product_search_service + + +class ListProductSetsPager: + """A pager for iterating through ``list_product_sets`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListProductSetsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``product_sets`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProductSets`` requests and continue to iterate + through the ``product_sets`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListProductSetsResponse` + 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[..., product_search_service.ListProductSetsResponse], + request: product_search_service.ListProductSetsRequest, + response: product_search_service.ListProductSetsResponse, + *, + 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.vision_v1.types.ListProductSetsRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListProductSetsResponse): + 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 = product_search_service.ListProductSetsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductSetsResponse]: + 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) -> Iterator[product_search_service.ProductSet]: + for page in self.pages: + yield from page.product_sets + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductSetsAsyncPager: + """A pager for iterating through ``list_product_sets`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListProductSetsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``product_sets`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProductSets`` requests and continue to iterate + through the ``product_sets`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListProductSetsResponse` + 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[product_search_service.ListProductSetsResponse]], + request: product_search_service.ListProductSetsRequest, + response: product_search_service.ListProductSetsResponse, + *, + 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.vision_v1.types.ListProductSetsRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListProductSetsResponse): + 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 = product_search_service.ListProductSetsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductSetsResponse]: + 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) -> AsyncIterator[product_search_service.ProductSet]: + async def async_generator(): + async for page in self.pages: + for response in page.product_sets: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListProductsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListProductsResponse` + 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[..., product_search_service.ListProductsResponse], + request: product_search_service.ListProductsRequest, + response: product_search_service.ListProductsResponse, + *, + 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.vision_v1.types.ListProductsRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListProductsResponse): + 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 = product_search_service.ListProductsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductsResponse]: + 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) -> Iterator[product_search_service.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsAsyncPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListProductsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListProductsResponse` + 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[product_search_service.ListProductsResponse]], + request: product_search_service.ListProductsRequest, + response: product_search_service.ListProductsResponse, + *, + 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.vision_v1.types.ListProductsRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListProductsResponse): + 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 = product_search_service.ListProductsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductsResponse]: + 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) -> AsyncIterator[product_search_service.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListReferenceImagesPager: + """A pager for iterating through ``list_reference_images`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``reference_images`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListReferenceImages`` requests and continue to iterate + through the ``reference_images`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` + 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[..., product_search_service.ListReferenceImagesResponse], + request: product_search_service.ListReferenceImagesRequest, + response: product_search_service.ListReferenceImagesResponse, + *, + 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.vision_v1.types.ListReferenceImagesRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListReferenceImagesResponse): + 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 = product_search_service.ListReferenceImagesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListReferenceImagesResponse]: + 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) -> Iterator[product_search_service.ReferenceImage]: + for page in self.pages: + yield from page.reference_images + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListReferenceImagesAsyncPager: + """A pager for iterating through ``list_reference_images`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``reference_images`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListReferenceImages`` requests and continue to iterate + through the ``reference_images`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` + 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[product_search_service.ListReferenceImagesResponse]], + request: product_search_service.ListReferenceImagesRequest, + response: product_search_service.ListReferenceImagesResponse, + *, + 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.vision_v1.types.ListReferenceImagesRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListReferenceImagesResponse): + 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 = product_search_service.ListReferenceImagesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListReferenceImagesResponse]: + 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) -> AsyncIterator[product_search_service.ReferenceImage]: + async def async_generator(): + async for page in self.pages: + for response in page.reference_images: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsInProductSetPager: + """A pager for iterating through ``list_products_in_product_set`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProductsInProductSet`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` + 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[..., product_search_service.ListProductsInProductSetResponse], + request: product_search_service.ListProductsInProductSetRequest, + response: product_search_service.ListProductsInProductSetResponse, + *, + 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.vision_v1.types.ListProductsInProductSetRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListProductsInProductSetResponse): + 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 = product_search_service.ListProductsInProductSetRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductsInProductSetResponse]: + 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) -> Iterator[product_search_service.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsInProductSetAsyncPager: + """A pager for iterating through ``list_products_in_product_set`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProductsInProductSet`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` + 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[product_search_service.ListProductsInProductSetResponse]], + request: product_search_service.ListProductsInProductSetRequest, + response: product_search_service.ListProductsInProductSetResponse, + *, + 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.vision_v1.types.ListProductsInProductSetRequest): + The initial request object. + response (google.cloud.vision_v1.types.ListProductsInProductSetResponse): + 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 = product_search_service.ListProductsInProductSetRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductsInProductSetResponse]: + 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) -> AsyncIterator[product_search_service.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + 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/v1/google/cloud/vision_v1/services/product_search/transports/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/__init__.py new file mode 100644 index 00000000..22b20282 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/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 ProductSearchTransport +from .grpc import ProductSearchGrpcTransport +from .grpc_asyncio import ProductSearchGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductSearchTransport]] +_transport_registry['grpc'] = ProductSearchGrpcTransport +_transport_registry['grpc_asyncio'] = ProductSearchGrpcAsyncIOTransport + +__all__ = ( + 'ProductSearchTransport', + 'ProductSearchGrpcTransport', + 'ProductSearchGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py new file mode 100644 index 00000000..eb6258c0 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py @@ -0,0 +1,561 @@ +# -*- 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.vision_v1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-vision', + ).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 ProductSearchTransport(abc.ABC): + """Abstract transport class for ProductSearch.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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.create_product_set: gapic_v1.method.wrap_method( + self.create_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_product_sets: gapic_v1.method.wrap_method( + self.list_product_sets, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_product_set: gapic_v1.method.wrap_method( + self.get_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.update_product_set: gapic_v1.method.wrap_method( + self.update_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_product_set: gapic_v1.method.wrap_method( + self.delete_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.create_product: gapic_v1.method.wrap_method( + self.create_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_products: gapic_v1.method.wrap_method( + self.list_products, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_product: gapic_v1.method.wrap_method( + self.get_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.update_product: gapic_v1.method.wrap_method( + self.update_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_product: gapic_v1.method.wrap_method( + self.delete_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.create_reference_image: gapic_v1.method.wrap_method( + self.create_reference_image, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_reference_image: gapic_v1.method.wrap_method( + self.delete_reference_image, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_reference_images: gapic_v1.method.wrap_method( + self.list_reference_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_reference_image: gapic_v1.method.wrap_method( + self.get_reference_image, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.add_product_to_product_set: gapic_v1.method.wrap_method( + self.add_product_to_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.remove_product_from_product_set: gapic_v1.method.wrap_method( + self.remove_product_from_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_products_in_product_set: gapic_v1.method.wrap_method( + self.list_products_in_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.import_product_sets: gapic_v1.method.wrap_method( + self.import_product_sets, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.purge_products: gapic_v1.method.wrap_method( + self.purge_products, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + Union[ + product_search_service.ListProductSetsResponse, + Awaitable[product_search_service.ListProductSetsResponse] + ]]: + raise NotImplementedError() + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + Union[ + product_search_service.ListProductsResponse, + Awaitable[product_search_service.ListProductsResponse] + ]]: + raise NotImplementedError() + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + Union[ + product_search_service.ReferenceImage, + Awaitable[product_search_service.ReferenceImage] + ]]: + raise NotImplementedError() + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + Union[ + product_search_service.ListReferenceImagesResponse, + Awaitable[product_search_service.ListReferenceImagesResponse] + ]]: + raise NotImplementedError() + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + Union[ + product_search_service.ReferenceImage, + Awaitable[product_search_service.ReferenceImage] + ]]: + raise NotImplementedError() + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + Union[ + product_search_service.ListProductsInProductSetResponse, + Awaitable[product_search_service.ListProductsInProductSetResponse] + ]]: + raise NotImplementedError() + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def purge_products(self) -> Callable[ + [product_search_service.PurgeProductsRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ProductSearchTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py new file mode 100644 index 00000000..d84f625f --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py @@ -0,0 +1,912 @@ +# -*- 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.vision_v1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO + + +class ProductSearchGrpcTransport(ProductSearchTransport): + """gRPC backend transport for ProductSearch. + + Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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 create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the create product set method over gRPC. + + Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Returns: + Callable[[~.CreateProductSetRequest], + ~.ProductSet]: + 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_product_set' not in self._stubs: + self._stubs['create_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/CreateProductSet', + request_serializer=product_search_service.CreateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['create_product_set'] + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + product_search_service.ListProductSetsResponse]: + r"""Return a callable for the list product sets method over gRPC. + + Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Returns: + Callable[[~.ListProductSetsRequest], + ~.ListProductSetsResponse]: + 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_product_sets' not in self._stubs: + self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListProductSets', + request_serializer=product_search_service.ListProductSetsRequest.serialize, + response_deserializer=product_search_service.ListProductSetsResponse.deserialize, + ) + return self._stubs['list_product_sets'] + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the get product set method over gRPC. + + Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.GetProductSetRequest], + ~.ProductSet]: + 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 'get_product_set' not in self._stubs: + self._stubs['get_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/GetProductSet', + request_serializer=product_search_service.GetProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['get_product_set'] + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the update product set method over gRPC. + + Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Returns: + Callable[[~.UpdateProductSetRequest], + ~.ProductSet]: + 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 'update_product_set' not in self._stubs: + self._stubs['update_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/UpdateProductSet', + request_serializer=product_search_service.UpdateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['update_product_set'] + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product set method over gRPC. + + Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteProductSetRequest], + ~.Empty]: + 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_product_set' not in self._stubs: + self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/DeleteProductSet', + request_serializer=product_search_service.DeleteProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_set'] + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + product_search_service.Product]: + r"""Return a callable for the create product method over gRPC. + + Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Returns: + Callable[[~.CreateProductRequest], + ~.Product]: + 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_product' not in self._stubs: + self._stubs['create_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/CreateProduct', + request_serializer=product_search_service.CreateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['create_product'] + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + product_search_service.ListProductsResponse]: + r"""Return a callable for the list products method over gRPC. + + Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsRequest], + ~.ListProductsResponse]: + 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_products' not in self._stubs: + self._stubs['list_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListProducts', + request_serializer=product_search_service.ListProductsRequest.serialize, + response_deserializer=product_search_service.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + product_search_service.Product]: + r"""Return a callable for the get product method over gRPC. + + Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Returns: + Callable[[~.GetProductRequest], + ~.Product]: + 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 'get_product' not in self._stubs: + self._stubs['get_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/GetProduct', + request_serializer=product_search_service.GetProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + product_search_service.Product]: + r"""Return a callable for the update product method over gRPC. + + Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Returns: + Callable[[~.UpdateProductRequest], + ~.Product]: + 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 'update_product' not in self._stubs: + self._stubs['update_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/UpdateProduct', + request_serializer=product_search_service.UpdateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['update_product'] + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product method over gRPC. + + Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Returns: + Callable[[~.DeleteProductRequest], + ~.Empty]: + 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_product' not in self._stubs: + self._stubs['delete_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/DeleteProduct', + request_serializer=product_search_service.DeleteProductRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product'] + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + product_search_service.ReferenceImage]: + r"""Return a callable for the create reference image method over gRPC. + + Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Returns: + Callable[[~.CreateReferenceImageRequest], + ~.ReferenceImage]: + 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_reference_image' not in self._stubs: + self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/CreateReferenceImage', + request_serializer=product_search_service.CreateReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['create_reference_image'] + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete reference image method over gRPC. + + Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteReferenceImageRequest], + ~.Empty]: + 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_reference_image' not in self._stubs: + self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/DeleteReferenceImage', + request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_reference_image'] + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + product_search_service.ListReferenceImagesResponse]: + r"""Return a callable for the list reference images method over gRPC. + + Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Returns: + Callable[[~.ListReferenceImagesRequest], + ~.ListReferenceImagesResponse]: + 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_reference_images' not in self._stubs: + self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListReferenceImages', + request_serializer=product_search_service.ListReferenceImagesRequest.serialize, + response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, + ) + return self._stubs['list_reference_images'] + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + product_search_service.ReferenceImage]: + r"""Return a callable for the get reference image method over gRPC. + + Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Returns: + Callable[[~.GetReferenceImageRequest], + ~.ReferenceImage]: + 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 'get_reference_image' not in self._stubs: + self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/GetReferenceImage', + request_serializer=product_search_service.GetReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['get_reference_image'] + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the add product to product set method over gRPC. + + Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Returns: + Callable[[~.AddProductToProductSetRequest], + ~.Empty]: + 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 'add_product_to_product_set' not in self._stubs: + self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/AddProductToProductSet', + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['add_product_to_product_set'] + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the remove product from product + set method over gRPC. + + Removes a Product from the specified ProductSet. + + Returns: + Callable[[~.RemoveProductFromProductSetRequest], + ~.Empty]: + 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 'remove_product_from_product_set' not in self._stubs: + self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet', + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['remove_product_from_product_set'] + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + product_search_service.ListProductsInProductSetResponse]: + r"""Return a callable for the list products in product set method over gRPC. + + Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsInProductSetRequest], + ~.ListProductsInProductSetResponse]: + 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_products_in_product_set' not in self._stubs: + self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet', + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) + return self._stubs['list_products_in_product_set'] + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + operations_pb2.Operation]: + r"""Return a callable for the import product sets method over gRPC. + + Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + + Returns: + Callable[[~.ImportProductSetsRequest], + ~.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 'import_product_sets' not in self._stubs: + self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ImportProductSets', + request_serializer=product_search_service.ImportProductSetsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['import_product_sets'] + + @property + def purge_products(self) -> Callable[ + [product_search_service.PurgeProductsRequest], + operations_pb2.Operation]: + r"""Return a callable for the purge products method over gRPC. + + Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Returns: + Callable[[~.PurgeProductsRequest], + ~.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 'purge_products' not in self._stubs: + self._stubs['purge_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/PurgeProducts', + request_serializer=product_search_service.PurgeProductsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['purge_products'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ProductSearchGrpcTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py new file mode 100644 index 00000000..95a951f5 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py @@ -0,0 +1,917 @@ +# -*- 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.vision_v1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductSearchGrpcTransport + + +class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): + """gRPC AsyncIO backend transport for ProductSearch. + + Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1.ProductSet] resources, named + ``projects/*/locations/*/productSets/*``, which acts as a way to + put different products into groups to limit identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1.Product] has a collection + of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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 create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the create product set method over gRPC. + + Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Returns: + Callable[[~.CreateProductSetRequest], + Awaitable[~.ProductSet]]: + 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_product_set' not in self._stubs: + self._stubs['create_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/CreateProductSet', + request_serializer=product_search_service.CreateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['create_product_set'] + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + Awaitable[product_search_service.ListProductSetsResponse]]: + r"""Return a callable for the list product sets method over gRPC. + + Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Returns: + Callable[[~.ListProductSetsRequest], + Awaitable[~.ListProductSetsResponse]]: + 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_product_sets' not in self._stubs: + self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListProductSets', + request_serializer=product_search_service.ListProductSetsRequest.serialize, + response_deserializer=product_search_service.ListProductSetsResponse.deserialize, + ) + return self._stubs['list_product_sets'] + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the get product set method over gRPC. + + Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.GetProductSetRequest], + Awaitable[~.ProductSet]]: + 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 'get_product_set' not in self._stubs: + self._stubs['get_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/GetProductSet', + request_serializer=product_search_service.GetProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['get_product_set'] + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the update product set method over gRPC. + + Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Returns: + Callable[[~.UpdateProductSetRequest], + Awaitable[~.ProductSet]]: + 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 'update_product_set' not in self._stubs: + self._stubs['update_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/UpdateProductSet', + request_serializer=product_search_service.UpdateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['update_product_set'] + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product set method over gRPC. + + Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteProductSetRequest], + Awaitable[~.Empty]]: + 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_product_set' not in self._stubs: + self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/DeleteProductSet', + request_serializer=product_search_service.DeleteProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_set'] + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the create product method over gRPC. + + Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Returns: + Callable[[~.CreateProductRequest], + Awaitable[~.Product]]: + 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_product' not in self._stubs: + self._stubs['create_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/CreateProduct', + request_serializer=product_search_service.CreateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['create_product'] + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + Awaitable[product_search_service.ListProductsResponse]]: + r"""Return a callable for the list products method over gRPC. + + Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsRequest], + Awaitable[~.ListProductsResponse]]: + 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_products' not in self._stubs: + self._stubs['list_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListProducts', + request_serializer=product_search_service.ListProductsRequest.serialize, + response_deserializer=product_search_service.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the get product method over gRPC. + + Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Returns: + Callable[[~.GetProductRequest], + Awaitable[~.Product]]: + 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 'get_product' not in self._stubs: + self._stubs['get_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/GetProduct', + request_serializer=product_search_service.GetProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the update product method over gRPC. + + Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Returns: + Callable[[~.UpdateProductRequest], + Awaitable[~.Product]]: + 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 'update_product' not in self._stubs: + self._stubs['update_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/UpdateProduct', + request_serializer=product_search_service.UpdateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['update_product'] + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product method over gRPC. + + Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Returns: + Callable[[~.DeleteProductRequest], + Awaitable[~.Empty]]: + 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_product' not in self._stubs: + self._stubs['delete_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/DeleteProduct', + request_serializer=product_search_service.DeleteProductRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product'] + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + Awaitable[product_search_service.ReferenceImage]]: + r"""Return a callable for the create reference image method over gRPC. + + Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Returns: + Callable[[~.CreateReferenceImageRequest], + Awaitable[~.ReferenceImage]]: + 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_reference_image' not in self._stubs: + self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/CreateReferenceImage', + request_serializer=product_search_service.CreateReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['create_reference_image'] + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete reference image method over gRPC. + + Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteReferenceImageRequest], + Awaitable[~.Empty]]: + 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_reference_image' not in self._stubs: + self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/DeleteReferenceImage', + request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_reference_image'] + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + Awaitable[product_search_service.ListReferenceImagesResponse]]: + r"""Return a callable for the list reference images method over gRPC. + + Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Returns: + Callable[[~.ListReferenceImagesRequest], + Awaitable[~.ListReferenceImagesResponse]]: + 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_reference_images' not in self._stubs: + self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListReferenceImages', + request_serializer=product_search_service.ListReferenceImagesRequest.serialize, + response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, + ) + return self._stubs['list_reference_images'] + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + Awaitable[product_search_service.ReferenceImage]]: + r"""Return a callable for the get reference image method over gRPC. + + Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Returns: + Callable[[~.GetReferenceImageRequest], + Awaitable[~.ReferenceImage]]: + 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 'get_reference_image' not in self._stubs: + self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/GetReferenceImage', + request_serializer=product_search_service.GetReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['get_reference_image'] + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the add product to product set method over gRPC. + + Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Returns: + Callable[[~.AddProductToProductSetRequest], + Awaitable[~.Empty]]: + 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 'add_product_to_product_set' not in self._stubs: + self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/AddProductToProductSet', + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['add_product_to_product_set'] + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the remove product from product + set method over gRPC. + + Removes a Product from the specified ProductSet. + + Returns: + Callable[[~.RemoveProductFromProductSetRequest], + Awaitable[~.Empty]]: + 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 'remove_product_from_product_set' not in self._stubs: + self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet', + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['remove_product_from_product_set'] + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + Awaitable[product_search_service.ListProductsInProductSetResponse]]: + r"""Return a callable for the list products in product set method over gRPC. + + Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsInProductSetRequest], + Awaitable[~.ListProductsInProductSetResponse]]: + 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_products_in_product_set' not in self._stubs: + self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet', + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) + return self._stubs['list_products_in_product_set'] + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the import product sets method over gRPC. + + Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. + + Returns: + Callable[[~.ImportProductSetsRequest], + 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 'import_product_sets' not in self._stubs: + self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/ImportProductSets', + request_serializer=product_search_service.ImportProductSetsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['import_product_sets'] + + @property + def purge_products(self) -> Callable[ + [product_search_service.PurgeProductsRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the purge products method over gRPC. + + Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Returns: + Callable[[~.PurgeProductsRequest], + 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 'purge_products' not in self._stubs: + self._stubs['purge_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1.ProductSearch/PurgeProducts', + request_serializer=product_search_service.PurgeProductsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['purge_products'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ProductSearchGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py new file mode 100644 index 00000000..c652d4b2 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py @@ -0,0 +1,198 @@ +# -*- 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 .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) +from .image_annotator import ( + AnnotateFileRequest, + AnnotateFileResponse, + AnnotateImageRequest, + AnnotateImageResponse, + AsyncAnnotateFileRequest, + AsyncAnnotateFileResponse, + AsyncBatchAnnotateFilesRequest, + AsyncBatchAnnotateFilesResponse, + AsyncBatchAnnotateImagesRequest, + AsyncBatchAnnotateImagesResponse, + BatchAnnotateFilesRequest, + BatchAnnotateFilesResponse, + BatchAnnotateImagesRequest, + BatchAnnotateImagesResponse, + ColorInfo, + CropHint, + CropHintsAnnotation, + CropHintsParams, + DominantColorsAnnotation, + EntityAnnotation, + FaceAnnotation, + Feature, + GcsDestination, + GcsSource, + Image, + ImageAnnotationContext, + ImageContext, + ImageProperties, + ImageSource, + InputConfig, + LatLongRect, + LocalizedObjectAnnotation, + LocationInfo, + OperationMetadata, + OutputConfig, + Property, + SafeSearchAnnotation, + TextDetectionParams, + WebDetectionParams, + Likelihood, +) +from .product_search import ( + ProductSearchParams, + ProductSearchResults, +) +from .product_search_service import ( + AddProductToProductSetRequest, + BatchOperationMetadata, + CreateProductRequest, + CreateProductSetRequest, + CreateReferenceImageRequest, + DeleteProductRequest, + DeleteProductSetRequest, + DeleteReferenceImageRequest, + GetProductRequest, + GetProductSetRequest, + GetReferenceImageRequest, + ImportProductSetsGcsSource, + ImportProductSetsInputConfig, + ImportProductSetsRequest, + ImportProductSetsResponse, + ListProductSetsRequest, + ListProductSetsResponse, + ListProductsInProductSetRequest, + ListProductsInProductSetResponse, + ListProductsRequest, + ListProductsResponse, + ListReferenceImagesRequest, + ListReferenceImagesResponse, + Product, + ProductSet, + ProductSetPurgeConfig, + PurgeProductsRequest, + ReferenceImage, + RemoveProductFromProductSetRequest, + UpdateProductRequest, + UpdateProductSetRequest, +) +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) + +__all__ = ( + 'BoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileRequest', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'AsyncBatchAnnotateImagesRequest', + 'AsyncBatchAnnotateImagesResponse', + 'BatchAnnotateFilesRequest', + 'BatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocalizedObjectAnnotation', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'ProductSearchParams', + 'ProductSearchResults', + 'AddProductToProductSetRequest', + 'BatchOperationMetadata', + 'CreateProductRequest', + 'CreateProductSetRequest', + 'CreateReferenceImageRequest', + 'DeleteProductRequest', + 'DeleteProductSetRequest', + 'DeleteReferenceImageRequest', + 'GetProductRequest', + 'GetProductSetRequest', + 'GetReferenceImageRequest', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ListProductsRequest', + 'ListProductsResponse', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'Product', + 'ProductSet', + 'ProductSetPurgeConfig', + 'PurgeProductsRequest', + 'ReferenceImage', + 'RemoveProductFromProductSetRequest', + 'UpdateProductRequest', + 'UpdateProductSetRequest', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py new file mode 100644 index 00000000..f938d235 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py @@ -0,0 +1,125 @@ +# -*- 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.vision.v1', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + 'Position', + }, +) + + +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.vision_v1.types.Vertex]): + The bounding polygon vertices. + normalized_vertices (Sequence[google.cloud.vision_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', + ) + + +class Position(proto.Message): + r"""A 3D position in the image, used primarily for Face detection + landmarks. A valid Position must have both x and y coordinates. + The position coordinates are in the same scale as the original + image. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate. + z (float): + Z coordinate (or depth). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + z = proto.Field( + proto.FLOAT, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py new file mode 100644 index 00000000..a5e7fc0b --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py @@ -0,0 +1,1612 @@ +# -*- 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.vision_v1.types import geometry +from google.cloud.vision_v1.types import product_search +from google.cloud.vision_v1.types import text_annotation +from google.cloud.vision_v1.types import web_detection as gcv_web_detection +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 latlng_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1', + manifest={ + 'Likelihood', + 'Feature', + 'ImageSource', + 'Image', + 'FaceAnnotation', + 'LocationInfo', + 'Property', + 'EntityAnnotation', + 'LocalizedObjectAnnotation', + 'SafeSearchAnnotation', + 'LatLongRect', + 'ColorInfo', + 'DominantColorsAnnotation', + 'ImageProperties', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'WebDetectionParams', + 'TextDetectionParams', + 'ImageContext', + 'AnnotateImageRequest', + 'ImageAnnotationContext', + 'AnnotateImageResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'AnnotateFileRequest', + 'AnnotateFileResponse', + 'BatchAnnotateFilesRequest', + 'BatchAnnotateFilesResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateImagesRequest', + 'AsyncBatchAnnotateImagesResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'InputConfig', + 'OutputConfig', + 'GcsSource', + 'GcsDestination', + 'OperationMetadata', + }, +) + + +class Likelihood(proto.Enum): + r"""A bucketized representation of likelihood, which is intended + to give clients highly stable results across model upgrades. + """ + UNKNOWN = 0 + VERY_UNLIKELY = 1 + UNLIKELY = 2 + POSSIBLE = 3 + LIKELY = 4 + VERY_LIKELY = 5 + + +class Feature(proto.Message): + r"""The type of Google Cloud Vision API detection to perform, and the + maximum number of results to return for that type. Multiple + ``Feature`` objects can be specified in the ``features`` list. + + Attributes: + type_ (google.cloud.vision_v1.types.Feature.Type): + The feature type. + max_results (int): + Maximum number of results of this type. Does not apply to + ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or + ``CROP_HINTS``. + model (str): + Model to use for the feature. + Supported values: "builtin/stable" (the default + if unset) and "builtin/latest". + """ + class Type(proto.Enum): + r"""Type of Google Cloud Vision API feature to be extracted.""" + TYPE_UNSPECIFIED = 0 + FACE_DETECTION = 1 + LANDMARK_DETECTION = 2 + LOGO_DETECTION = 3 + LABEL_DETECTION = 4 + TEXT_DETECTION = 5 + DOCUMENT_TEXT_DETECTION = 11 + SAFE_SEARCH_DETECTION = 6 + IMAGE_PROPERTIES = 7 + CROP_HINTS = 9 + WEB_DETECTION = 10 + PRODUCT_SEARCH = 12 + OBJECT_LOCALIZATION = 19 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum=Type, + ) + max_results = proto.Field( + proto.INT32, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + + +class ImageSource(proto.Message): + r"""External image source (Google Cloud Storage or web URL image + location). + + Attributes: + gcs_image_uri (str): + **Use ``image_uri`` instead.** + + The 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. + image_uri (str): + The URI of the source image. Can be either: + + 1. A 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. + + 2. A publicly-accessible image HTTP/HTTPS URL. When fetching + images from HTTP/HTTPS URLs, Google cannot guarantee that + the request will be completed. Your request may fail if + the specified host denies the request (e.g. due to + request throttling or DOS prevention), or if Google + throttles requests to the site for abuse prevention. You + should not depend on externally-hosted images for + production applications. + + When both ``gcs_image_uri`` and ``image_uri`` are specified, + ``image_uri`` takes precedence. + """ + + gcs_image_uri = proto.Field( + proto.STRING, + number=1, + ) + image_uri = proto.Field( + proto.STRING, + number=2, + ) + + +class Image(proto.Message): + r"""Client image to perform Google Cloud Vision API tasks over. + + Attributes: + content (bytes): + Image content, represented as a stream of bytes. Note: As + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + + Currently, this field only works for BatchAnnotateImages + requests. It does not work for AsyncBatchAnnotateImages + requests. + source (google.cloud.vision_v1.types.ImageSource): + Google Cloud Storage image location, or publicly-accessible + image URL. If both ``content`` and ``source`` are provided + for an image, ``content`` takes precedence and is used to + perform the image annotation request. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + source = proto.Field( + proto.MESSAGE, + number=2, + message='ImageSource', + ) + + +class FaceAnnotation(proto.Message): + r"""A face annotation object contains the results of face + detection. + + Attributes: + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + The bounding polygon around the face. The coordinates of the + bounding box are in the original image's scale. The bounding + box is computed to "frame" the face in accordance with human + expectations. It is based on the landmarker results. Note + that one or more x and/or y coordinates may not be generated + in the ``BoundingPoly`` (the polygon will be unbounded) if + only a partial face appears in the image to be annotated. + fd_bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + The ``fd_bounding_poly`` bounding polygon is tighter than + the ``boundingPoly``, and encloses only the skin part of the + face. Typically, it is used to eliminate the face from any + image analysis that detects the "amount of skin" visible in + an image. It is not based on the landmarker results, only on + the initial face detection, hence the fd (face detection) + prefix. + landmarks (Sequence[google.cloud.vision_v1.types.FaceAnnotation.Landmark]): + Detected face landmarks. + roll_angle (float): + Roll angle, which indicates the amount of + clockwise/anti-clockwise rotation of the face relative to + the image vertical about the axis perpendicular to the face. + Range [-180,180]. + pan_angle (float): + Yaw angle, which indicates the leftward/rightward angle that + the face is pointing relative to the vertical plane + perpendicular to the image. Range [-180,180]. + tilt_angle (float): + Pitch angle, which indicates the upwards/downwards angle + that the face is pointing relative to the image's horizontal + plane. Range [-180,180]. + detection_confidence (float): + Detection confidence. Range [0, 1]. + landmarking_confidence (float): + Face landmarking confidence. Range [0, 1]. + joy_likelihood (google.cloud.vision_v1.types.Likelihood): + Joy likelihood. + sorrow_likelihood (google.cloud.vision_v1.types.Likelihood): + Sorrow likelihood. + anger_likelihood (google.cloud.vision_v1.types.Likelihood): + Anger likelihood. + surprise_likelihood (google.cloud.vision_v1.types.Likelihood): + Surprise likelihood. + under_exposed_likelihood (google.cloud.vision_v1.types.Likelihood): + Under-exposed likelihood. + blurred_likelihood (google.cloud.vision_v1.types.Likelihood): + Blurred likelihood. + headwear_likelihood (google.cloud.vision_v1.types.Likelihood): + Headwear likelihood. + """ + + class Landmark(proto.Message): + r"""A face-specific landmark (for example, a face feature). + + Attributes: + type_ (google.cloud.vision_v1.types.FaceAnnotation.Landmark.Type): + Face landmark type. + position (google.cloud.vision_v1.types.Position): + Face landmark position. + """ + class Type(proto.Enum): + r"""Face landmark (feature) type. Left and right are defined from the + vantage of the viewer of the image without considering mirror + projections typical of photos. So, ``LEFT_EYE``, typically, is the + person's right eye. + """ + UNKNOWN_LANDMARK = 0 + LEFT_EYE = 1 + RIGHT_EYE = 2 + LEFT_OF_LEFT_EYEBROW = 3 + RIGHT_OF_LEFT_EYEBROW = 4 + LEFT_OF_RIGHT_EYEBROW = 5 + RIGHT_OF_RIGHT_EYEBROW = 6 + MIDPOINT_BETWEEN_EYES = 7 + NOSE_TIP = 8 + UPPER_LIP = 9 + LOWER_LIP = 10 + MOUTH_LEFT = 11 + MOUTH_RIGHT = 12 + MOUTH_CENTER = 13 + NOSE_BOTTOM_RIGHT = 14 + NOSE_BOTTOM_LEFT = 15 + NOSE_BOTTOM_CENTER = 16 + LEFT_EYE_TOP_BOUNDARY = 17 + LEFT_EYE_RIGHT_CORNER = 18 + LEFT_EYE_BOTTOM_BOUNDARY = 19 + LEFT_EYE_LEFT_CORNER = 20 + RIGHT_EYE_TOP_BOUNDARY = 21 + RIGHT_EYE_RIGHT_CORNER = 22 + RIGHT_EYE_BOTTOM_BOUNDARY = 23 + RIGHT_EYE_LEFT_CORNER = 24 + LEFT_EYEBROW_UPPER_MIDPOINT = 25 + RIGHT_EYEBROW_UPPER_MIDPOINT = 26 + LEFT_EAR_TRAGION = 27 + RIGHT_EAR_TRAGION = 28 + LEFT_EYE_PUPIL = 29 + RIGHT_EYE_PUPIL = 30 + FOREHEAD_GLABELLA = 31 + CHIN_GNATHION = 32 + CHIN_LEFT_GONION = 33 + CHIN_RIGHT_GONION = 34 + LEFT_CHEEK_CENTER = 35 + RIGHT_CHEEK_CENTER = 36 + + type_ = proto.Field( + proto.ENUM, + number=3, + enum='FaceAnnotation.Landmark.Type', + ) + position = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.Position, + ) + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + fd_bounding_poly = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + landmarks = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Landmark, + ) + roll_angle = proto.Field( + proto.FLOAT, + number=4, + ) + pan_angle = proto.Field( + proto.FLOAT, + number=5, + ) + tilt_angle = proto.Field( + proto.FLOAT, + number=6, + ) + detection_confidence = proto.Field( + proto.FLOAT, + number=7, + ) + landmarking_confidence = proto.Field( + proto.FLOAT, + number=8, + ) + joy_likelihood = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + sorrow_likelihood = proto.Field( + proto.ENUM, + number=10, + enum='Likelihood', + ) + anger_likelihood = proto.Field( + proto.ENUM, + number=11, + enum='Likelihood', + ) + surprise_likelihood = proto.Field( + proto.ENUM, + number=12, + enum='Likelihood', + ) + under_exposed_likelihood = proto.Field( + proto.ENUM, + number=13, + enum='Likelihood', + ) + blurred_likelihood = proto.Field( + proto.ENUM, + number=14, + enum='Likelihood', + ) + headwear_likelihood = proto.Field( + proto.ENUM, + number=15, + enum='Likelihood', + ) + + +class LocationInfo(proto.Message): + r"""Detected entity location information. + + Attributes: + lat_lng (google.type.latlng_pb2.LatLng): + lat/long location coordinates. + """ + + lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + + +class Property(proto.Message): + r"""A ``Property`` consists of a user-supplied name/value pair. + + Attributes: + name (str): + Name of the property. + value (str): + Value of the property. + uint64_value (int): + Value of numeric properties. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + uint64_value = proto.Field( + proto.UINT64, + number=3, + ) + + +class EntityAnnotation(proto.Message): + r"""Set of detected entity features. + + Attributes: + mid (str): + Opaque entity ID. Some IDs may be available in `Google + Knowledge Graph Search + API `__. + locale (str): + The language code for the locale in which the entity textual + ``description`` is expressed. + description (str): + Entity textual description, expressed in its ``locale`` + language. + score (float): + Overall score of the result. Range [0, 1]. + confidence (float): + **Deprecated. Use ``score`` instead.** The accuracy of the + entity detection in an image. For example, for an image in + which the "Eiffel Tower" entity is detected, this field + represents the confidence that there is a tower in the query + image. Range [0, 1]. + topicality (float): + The relevancy of the ICA (Image Content Annotation) label to + the image. For example, the relevancy of "tower" is likely + higher to an image containing the detected "Eiffel Tower" + than to an image containing a detected distant towering + building, even though the confidence that there is a tower + in each image may be the same. Range [0, 1]. + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + Image region to which this entity belongs. Not produced for + ``LABEL_DETECTION`` features. + locations (Sequence[google.cloud.vision_v1.types.LocationInfo]): + The location information for the detected entity. Multiple + ``LocationInfo`` elements can be present because one + location may indicate the location of the scene in the + image, and another location may indicate the location of the + place where the image was taken. Location information is + usually present for landmarks. + properties (Sequence[google.cloud.vision_v1.types.Property]): + Some entities may have optional user-supplied ``Property`` + (name/value) fields, such a score or string that qualifies + the entity. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + locale = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + topicality = proto.Field( + proto.FLOAT, + number=6, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=7, + message=geometry.BoundingPoly, + ) + locations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='LocationInfo', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Property', + ) + + +class LocalizedObjectAnnotation(proto.Message): + r"""Set of detected objects with bounding boxes. + + Attributes: + mid (str): + Object ID that should align with + EntityAnnotation mid. + 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. + name (str): + Object name, expressed in its ``language_code`` language. + score (float): + Score of the result. Range [0, 1]. + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + Image region to which this object belongs. + This must be populated. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + name = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=5, + message=geometry.BoundingPoly, + ) + + +class SafeSearchAnnotation(proto.Message): + r"""Set of features pertaining to the image, computed by computer + vision methods over safe-search verticals (for example, adult, + spoof, medical, violence). + + Attributes: + adult (google.cloud.vision_v1.types.Likelihood): + Represents the adult content likelihood for + the image. Adult content may contain elements + such as nudity, pornographic images or cartoons, + or sexual activities. + spoof (google.cloud.vision_v1.types.Likelihood): + Spoof likelihood. The likelihood that an + modification was made to the image's canonical + version to make it appear funny or offensive. + medical (google.cloud.vision_v1.types.Likelihood): + Likelihood that this is a medical image. + violence (google.cloud.vision_v1.types.Likelihood): + Likelihood that this image contains violent + content. + racy (google.cloud.vision_v1.types.Likelihood): + Likelihood that the request image contains + racy content. Racy content may include (but is + not limited to) skimpy or sheer clothing, + strategically covered nudity, lewd or + provocative poses, or close-ups of sensitive + body areas. + adult_confidence (float): + Confidence of adult_score. Range [0, 1]. 0 means not + confident, 1 means very confident. + spoof_confidence (float): + Confidence of spoof_score. Range [0, 1]. 0 means not + confident, 1 means very confident. + medical_confidence (float): + Confidence of medical_score. Range [0, 1]. 0 means not + confident, 1 means very confident. + violence_confidence (float): + Confidence of violence_score. Range [0, 1]. 0 means not + confident, 1 means very confident. + racy_confidence (float): + Confidence of racy_score. Range [0, 1]. 0 means not + confident, 1 means very confident. + nsfw_confidence (float): + Confidence of nsfw_score. Range [0, 1]. 0 means not + confident, 1 means very confident. + """ + + adult = proto.Field( + proto.ENUM, + number=1, + enum='Likelihood', + ) + spoof = proto.Field( + proto.ENUM, + number=2, + enum='Likelihood', + ) + medical = proto.Field( + proto.ENUM, + number=3, + enum='Likelihood', + ) + violence = proto.Field( + proto.ENUM, + number=4, + enum='Likelihood', + ) + racy = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + adult_confidence = proto.Field( + proto.FLOAT, + number=16, + ) + spoof_confidence = proto.Field( + proto.FLOAT, + number=18, + ) + medical_confidence = proto.Field( + proto.FLOAT, + number=20, + ) + violence_confidence = proto.Field( + proto.FLOAT, + number=22, + ) + racy_confidence = proto.Field( + proto.FLOAT, + number=24, + ) + nsfw_confidence = proto.Field( + proto.FLOAT, + number=26, + ) + + +class LatLongRect(proto.Message): + r"""Rectangle determined by min and max ``LatLng`` pairs. + + Attributes: + min_lat_lng (google.type.latlng_pb2.LatLng): + Min lat/long pair. + max_lat_lng (google.type.latlng_pb2.LatLng): + Max lat/long pair. + """ + + min_lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + max_lat_lng = proto.Field( + proto.MESSAGE, + number=2, + message=latlng_pb2.LatLng, + ) + + +class ColorInfo(proto.Message): + r"""Color information consists of RGB channels, score, and the + fraction of the image that the color occupies in the image. + + Attributes: + color (google.type.color_pb2.Color): + RGB components of the color. + score (float): + Image-specific score for this color. Value in range [0, 1]. + pixel_fraction (float): + The fraction of pixels the color occupies in the image. + Value in range [0, 1]. + """ + + color = proto.Field( + proto.MESSAGE, + number=1, + message=color_pb2.Color, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + pixel_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class DominantColorsAnnotation(proto.Message): + r"""Set of dominant colors and their corresponding scores. + + Attributes: + colors (Sequence[google.cloud.vision_v1.types.ColorInfo]): + RGB color values with their score and pixel + fraction. + """ + + colors = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ColorInfo', + ) + + +class ImageProperties(proto.Message): + r"""Stores image properties, such as dominant colors. + + Attributes: + dominant_colors (google.cloud.vision_v1.types.DominantColorsAnnotation): + If present, dominant colors completed + successfully. + """ + + dominant_colors = proto.Field( + proto.MESSAGE, + number=1, + message='DominantColorsAnnotation', + ) + + +class CropHint(proto.Message): + r"""Single crop hint that is used to generate a new crop when + serving an image. + + Attributes: + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + The bounding polygon for the crop region. The + coordinates of the bounding box are in the + original image's scale. + confidence (float): + Confidence of this being a salient region. Range [0, 1]. + importance_fraction (float): + Fraction of importance of this salient region + with respect to the original image. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + importance_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class CropHintsAnnotation(proto.Message): + r"""Set of crop hints that are used to generate new crops when + serving images. + + Attributes: + crop_hints (Sequence[google.cloud.vision_v1.types.CropHint]): + Crop hint results. + """ + + crop_hints = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='CropHint', + ) + + +class CropHintsParams(proto.Message): + r"""Parameters for crop hints annotation request. + + Attributes: + aspect_ratios (Sequence[float]): + Aspect ratios in floats, representing the + ratio of the width to the height of the image. + For example, if the desired aspect ratio is 4/3, + the corresponding float value should be 1.33333. + If not specified, the best possible crop is + returned. The number of provided aspect ratios + is limited to a maximum of 16; any aspect ratios + provided after the 16th are ignored. + """ + + aspect_ratios = proto.RepeatedField( + proto.FLOAT, + number=1, + ) + + +class WebDetectionParams(proto.Message): + r"""Parameters for web detection request. + + Attributes: + include_geo_results (bool): + Whether to include results derived from the + geo information in the image. + """ + + include_geo_results = proto.Field( + proto.BOOL, + number=2, + ) + + +class TextDetectionParams(proto.Message): + r"""Parameters for text detections. This is used to control + TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. + + Attributes: + enable_text_detection_confidence_score (bool): + By default, Cloud Vision API only includes confidence score + for DOCUMENT_TEXT_DETECTION result. Set the flag to true to + include confidence score for TEXT_DETECTION as well. + """ + + enable_text_detection_confidence_score = proto.Field( + proto.BOOL, + number=9, + ) + + +class ImageContext(proto.Message): + r"""Image context and/or feature-specific parameters. + + Attributes: + lat_long_rect (google.cloud.vision_v1.types.LatLongRect): + Not used. + language_hints (Sequence[str]): + List of languages to use for TEXT_DETECTION. 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). + Text detection returns an error if one or more of the + specified languages is not one of the `supported + languages `__. + crop_hints_params (google.cloud.vision_v1.types.CropHintsParams): + Parameters for crop hints annotation request. + product_search_params (google.cloud.vision_v1.types.ProductSearchParams): + Parameters for product search. + web_detection_params (google.cloud.vision_v1.types.WebDetectionParams): + Parameters for web detection. + text_detection_params (google.cloud.vision_v1.types.TextDetectionParams): + Parameters for text detection and document + text detection. + """ + + lat_long_rect = proto.Field( + proto.MESSAGE, + number=1, + message='LatLongRect', + ) + language_hints = proto.RepeatedField( + proto.STRING, + number=2, + ) + crop_hints_params = proto.Field( + proto.MESSAGE, + number=4, + message='CropHintsParams', + ) + product_search_params = proto.Field( + proto.MESSAGE, + number=5, + message=product_search.ProductSearchParams, + ) + web_detection_params = proto.Field( + proto.MESSAGE, + number=6, + message='WebDetectionParams', + ) + text_detection_params = proto.Field( + proto.MESSAGE, + number=12, + message='TextDetectionParams', + ) + + +class AnnotateImageRequest(proto.Message): + r"""Request for performing Google Cloud Vision API tasks over a + user-provided image, with user-requested features, and with + context information. + + Attributes: + image (google.cloud.vision_v1.types.Image): + The image to be processed. + features (Sequence[google.cloud.vision_v1.types.Feature]): + Requested features. + image_context (google.cloud.vision_v1.types.ImageContext): + Additional context that may accompany the + image. + """ + + image = proto.Field( + proto.MESSAGE, + number=1, + message='Image', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + + +class ImageAnnotationContext(proto.Message): + r"""If an image was produced from a file (e.g. a PDF), this + message gives information about the source of that image. + + Attributes: + uri (str): + The URI of the file used to produce the + image. + page_number (int): + If the file was a PDF or TIFF, this field + gives the page number within the file used to + produce the image. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + page_number = proto.Field( + proto.INT32, + number=2, + ) + + +class AnnotateImageResponse(proto.Message): + r"""Response to an image annotation request. + + Attributes: + face_annotations (Sequence[google.cloud.vision_v1.types.FaceAnnotation]): + If present, face detection has completed + successfully. + landmark_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): + If present, landmark detection has completed + successfully. + logo_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): + If present, logo detection has completed + successfully. + label_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): + If present, label detection has completed + successfully. + localized_object_annotations (Sequence[google.cloud.vision_v1.types.LocalizedObjectAnnotation]): + If present, localized object detection has + completed successfully. This will be sorted + descending by confidence score. + text_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): + If present, text (OCR) detection has + completed successfully. + full_text_annotation (google.cloud.vision_v1.types.TextAnnotation): + If present, text (OCR) detection or document + (OCR) text detection has completed successfully. + This annotation provides the structural + hierarchy for the OCR detected text. + safe_search_annotation (google.cloud.vision_v1.types.SafeSearchAnnotation): + If present, safe-search annotation has + completed successfully. + image_properties_annotation (google.cloud.vision_v1.types.ImageProperties): + If present, image properties were extracted + successfully. + crop_hints_annotation (google.cloud.vision_v1.types.CropHintsAnnotation): + If present, crop hints have completed + successfully. + web_detection (google.cloud.vision_v1.types.WebDetection): + If present, web detection has completed + successfully. + product_search_results (google.cloud.vision_v1.types.ProductSearchResults): + If present, product search has completed + successfully. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the operation. Note + that filled-in image annotations are guaranteed to be + correct, even when ``error`` is set. + context (google.cloud.vision_v1.types.ImageAnnotationContext): + If present, contextual information is needed + to understand where this image comes from. + """ + + face_annotations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='FaceAnnotation', + ) + landmark_annotations = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='EntityAnnotation', + ) + logo_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='EntityAnnotation', + ) + label_annotations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='EntityAnnotation', + ) + localized_object_annotations = proto.RepeatedField( + proto.MESSAGE, + number=22, + message='LocalizedObjectAnnotation', + ) + text_annotations = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='EntityAnnotation', + ) + full_text_annotation = proto.Field( + proto.MESSAGE, + number=12, + message=text_annotation.TextAnnotation, + ) + safe_search_annotation = proto.Field( + proto.MESSAGE, + number=6, + message='SafeSearchAnnotation', + ) + image_properties_annotation = proto.Field( + proto.MESSAGE, + number=8, + message='ImageProperties', + ) + crop_hints_annotation = proto.Field( + proto.MESSAGE, + number=11, + message='CropHintsAnnotation', + ) + web_detection = proto.Field( + proto.MESSAGE, + number=13, + message=gcv_web_detection.WebDetection, + ) + product_search_results = proto.Field( + proto.MESSAGE, + number=14, + message=product_search.ProductSearchResults, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + context = proto.Field( + proto.MESSAGE, + number=21, + message='ImageAnnotationContext', + ) + + +class BatchAnnotateImagesRequest(proto.Message): + r"""Multiple image annotation requests are batched into a single + service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + parent (str): + Optional. Target project and location to make a call. + + Format: ``projects/{project-id}/locations/{location-id}``. + + If no parent is specified, a region will be chosen + automatically. + + Supported location-ids: ``us``: USA country only, ``asia``: + East asia areas, like Japan, Taiwan, ``eu``: The European + Union. + + Example: ``projects/project-A/locations/eu``. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + parent = proto.Field( + proto.STRING, + number=4, + ) + + +class BatchAnnotateImagesResponse(proto.Message): + r"""Response to a batch image annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): + Individual responses to image annotation + requests within the batch. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageResponse', + ) + + +class AnnotateFileRequest(proto.Message): + r"""A request to annotate one single file, e.g. a PDF, TIFF or + GIF file. + + Attributes: + input_config (google.cloud.vision_v1.types.InputConfig): + Required. Information about the input file. + features (Sequence[google.cloud.vision_v1.types.Feature]): + Required. Requested features. + image_context (google.cloud.vision_v1.types.ImageContext): + Additional context that may accompany the + image(s) in the file. + pages (Sequence[int]): + Pages of the file to perform image + annotation. + Pages starts from 1, we assume the first page of + the file is page 1. At most 5 pages are + supported per request. Pages can be negative. + Page 1 means the first page. + Page 2 means the second page. + Page -1 means the last page. + Page -2 means the second to the last page. + + If the file is GIF instead of PDF or TIFF, page + refers to GIF frames. + If this field is empty, by default the service + performs image annotation for the first 5 pages + of the file. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + pages = proto.RepeatedField( + proto.INT32, + number=4, + ) + + +class AnnotateFileResponse(proto.Message): + r"""Response to a single file annotation request. A file may + contain one or more images, which individually have their own + responses. + + Attributes: + input_config (google.cloud.vision_v1.types.InputConfig): + Information about the file for which this + response is generated. + responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): + Individual responses to images found within the file. This + field will be empty if the ``error`` field is set. + total_pages (int): + This field gives the total number of pages in + the file. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the failed request. + The ``responses`` field will not be set in this case. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + responses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='AnnotateImageResponse', + ) + total_pages = proto.Field( + proto.INT32, + number=3, + ) + error = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + + +class BatchAnnotateFilesRequest(proto.Message): + r"""A list of requests to annotate files using the + BatchAnnotateFiles API. + + Attributes: + requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]): + Required. The list of file annotation + requests. Right now we support only one + AnnotateFileRequest in + BatchAnnotateFilesRequest. + parent (str): + Optional. Target project and location to make a call. + + Format: ``projects/{project-id}/locations/{location-id}``. + + If no parent is specified, a region will be chosen + automatically. + + Supported location-ids: ``us``: USA country only, ``asia``: + East asia areas, like Japan, Taiwan, ``eu``: The European + Union. + + Example: ``projects/project-A/locations/eu``. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateFileRequest', + ) + parent = proto.Field( + proto.STRING, + number=3, + ) + + +class BatchAnnotateFilesResponse(proto.Message): + r"""A list of file annotation responses. + + Attributes: + responses (Sequence[google.cloud.vision_v1.types.AnnotateFileResponse]): + The list of file annotation responses, each + response corresponding to each + AnnotateFileRequest in + BatchAnnotateFilesRequest. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateFileResponse', + ) + + +class AsyncAnnotateFileRequest(proto.Message): + r"""An offline file annotation request. + + Attributes: + input_config (google.cloud.vision_v1.types.InputConfig): + Required. Information about the input file. + features (Sequence[google.cloud.vision_v1.types.Feature]): + Required. Requested features. + image_context (google.cloud.vision_v1.types.ImageContext): + Additional context that may accompany the + image(s) in the file. + output_config (google.cloud.vision_v1.types.OutputConfig): + Required. The desired output location and + metadata (e.g. format). + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + output_config = proto.Field( + proto.MESSAGE, + number=4, + message='OutputConfig', + ) + + +class AsyncAnnotateFileResponse(proto.Message): + r"""The response for a single offline file annotation request. + + Attributes: + output_config (google.cloud.vision_v1.types.OutputConfig): + The output location and metadata from + AsyncAnnotateFileRequest. + """ + + output_config = proto.Field( + proto.MESSAGE, + number=1, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateImagesRequest(proto.Message): + r"""Request for async image annotation for a list of images. + + Attributes: + requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + output_config (google.cloud.vision_v1.types.OutputConfig): + Required. The desired output location and + metadata (e.g. format). + parent (str): + Optional. Target project and location to make a call. + + Format: ``projects/{project-id}/locations/{location-id}``. + + If no parent is specified, a region will be chosen + automatically. + + Supported location-ids: ``us``: USA country only, ``asia``: + East asia areas, like Japan, Taiwan, ``eu``: The European + Union. + + Example: ``projects/project-A/locations/eu``. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message='OutputConfig', + ) + parent = proto.Field( + proto.STRING, + number=4, + ) + + +class AsyncBatchAnnotateImagesResponse(proto.Message): + r"""Response to an async batch image annotation request. + + Attributes: + output_config (google.cloud.vision_v1.types.OutputConfig): + The output location and metadata from + AsyncBatchAnnotateImagesRequest. + """ + + output_config = proto.Field( + proto.MESSAGE, + number=1, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateFilesRequest(proto.Message): + r"""Multiple async file annotation requests are batched into a + single service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]): + Required. Individual async file annotation + requests for this batch. + parent (str): + Optional. Target project and location to make a call. + + Format: ``projects/{project-id}/locations/{location-id}``. + + If no parent is specified, a region will be chosen + automatically. + + Supported location-ids: ``us``: USA country only, ``asia``: + East asia areas, like Japan, Taiwan, ``eu``: The European + Union. + + Example: ``projects/project-A/locations/eu``. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileRequest', + ) + parent = proto.Field( + proto.STRING, + number=4, + ) + + +class AsyncBatchAnnotateFilesResponse(proto.Message): + r"""Response to an async batch file annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileResponse]): + The list of file annotation responses, one + for each request in + AsyncBatchAnnotateFilesRequest. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileResponse', + ) + + +class InputConfig(proto.Message): + r"""The desired input location and metadata. + + Attributes: + gcs_source (google.cloud.vision_v1.types.GcsSource): + The Google Cloud Storage location to read the + input from. + content (bytes): + File content, represented as a stream of bytes. Note: As + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + + Currently, this field only works for BatchAnnotateFiles + requests. It does not work for AsyncBatchAnnotateFiles + requests. + mime_type (str): + The type of the file. Currently only + "application/pdf", "image/tiff" and "image/gif" + are supported. Wildcards are not supported. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message='GcsSource', + ) + content = proto.Field( + proto.BYTES, + number=3, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class OutputConfig(proto.Message): + r"""The desired output location and metadata. + + Attributes: + gcs_destination (google.cloud.vision_v1.types.GcsDestination): + The Google Cloud Storage location to write + the output(s) to. + batch_size (int): + The max number of response protos to put into each output + JSON file 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 response + protos will be generated. If ``batch_size`` = 20, then 5 + json files each containing 20 response protos will be + written under the prefix ``gcs_destination``.\ ``uri``. + + Currently, batch_size only applies to GcsDestination, with + potential future support for other output configurations. + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message='GcsDestination', + ) + batch_size = proto.Field( + proto.INT32, + number=2, + ) + + +class GcsSource(proto.Message): + r"""The Google Cloud Storage location where the input will be + read from. + + Attributes: + uri (str): + Google Cloud Storage URI for the input file. + This must only be a Google Cloud Storage object. + Wildcards are not currently supported. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class GcsDestination(proto.Message): + r"""The Google Cloud Storage location where the output will be + written to. + + Attributes: + uri (str): + Google Cloud Storage URI prefix where the results will be + stored. Results will be in JSON format and preceded by its + corresponding input URI prefix. This field can either + represent a gcs file prefix or gcs directory. In either + case, the uri should be unique because in order to get all + of the output files, you will need to do a wildcard gcs + search on the uri prefix you provide. + + Examples: + + - File Prefix: gs://bucket-name/here/filenameprefix The + output files will be created in gs://bucket-name/here/ + and the names of the output files will begin with + "filenameprefix". + + - Directory Prefix: gs://bucket-name/some/location/ The + output files will be created in + gs://bucket-name/some/location/ and the names of the + output files could be anything because there was no + filename prefix specified. + + If multiple outputs, each response is still + AnnotateFileResponse, each of which contains some subset of + the full list of AnnotateImageResponse. Multiple outputs can + happen if, for example, the output JSON is too large and + overflows into multiple sharded files. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class OperationMetadata(proto.Message): + r"""Contains metadata for the BatchAnnotateImages operation. + + Attributes: + state (google.cloud.vision_v1.types.OperationMetadata.State): + Current state of the batch operation. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was received. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the operation result was last + updated. + """ + class State(proto.Enum): + r"""Batch operation states.""" + STATE_UNSPECIFIED = 0 + CREATED = 1 + RUNNING = 2 + DONE = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py new file mode 100644 index 00000000..94fb4c70 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py @@ -0,0 +1,222 @@ +# -*- 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.vision_v1.types import geometry +from google.cloud.vision_v1.types import product_search_service +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1', + manifest={ + 'ProductSearchParams', + 'ProductSearchResults', + }, +) + + +class ProductSearchParams(proto.Message): + r"""Parameters for a product search request. + + Attributes: + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + The bounding polygon around the area of + interest in the image. If it is not specified, + system discretion will be applied. + product_set (str): + The resource name of a + [ProductSet][google.cloud.vision.v1.ProductSet] to be + searched for similar images. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. + product_categories (Sequence[str]): + The list of product categories to search in. + Currently, we only consider the first category, + and either "homegoods-v2", "apparel-v2", + "toys-v2", "packagedgoods-v1", or "general-v1" + should be specified. The legacy categories + "homegoods", "apparel", and "toys" are still + supported but will be deprecated. For new + products, please use "homegoods-v2", + "apparel-v2", or "toys-v2" for better product + search accuracy. It is recommended to migrate + existing products to these categories as well. + filter (str): + The filtering expression. This can be used to + restrict search results based on Product labels. + We currently support an AND of OR of key-value + expressions, where each expression within an OR + must have the same key. An '=' should be used to + connect the key and value. + For example, "(color = red OR color = blue) AND + brand = Google" is acceptable, but "(color = red + OR brand = Google)" is not acceptable. "color: + red" is not acceptable because it uses a ':' + instead of an '='. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=9, + message=geometry.BoundingPoly, + ) + product_set = proto.Field( + proto.STRING, + number=6, + ) + product_categories = proto.RepeatedField( + proto.STRING, + number=7, + ) + filter = proto.Field( + proto.STRING, + number=8, + ) + + +class ProductSearchResults(proto.Message): + r"""Results for a product search request. + + Attributes: + index_time (google.protobuf.timestamp_pb2.Timestamp): + Timestamp of the index which provided these + results. Products added to the product set and + products removed from the product set after this + time are not reflected in the current results. + results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.Result]): + List of results, one for each product match. + product_grouped_results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.GroupedResult]): + List of results grouped by products detected + in the query image. Each entry corresponds to + one bounding polygon in the query image, and + contains the matching products specific to that + region. There may be duplicate product matches + in the union of all the per-product results. + """ + + class Result(proto.Message): + r"""Information about a product. + + Attributes: + product (google.cloud.vision_v1.types.Product): + The Product. + score (float): + A confidence level on the match, ranging from + 0 (no confidence) to 1 (full confidence). + image (str): + The resource name of the image from the + product that is the closest match to the query. + """ + + product = proto.Field( + proto.MESSAGE, + number=1, + message=product_search_service.Product, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + image = proto.Field( + proto.STRING, + number=3, + ) + + class ObjectAnnotation(proto.Message): + r"""Prediction for what the object in the bounding box is. + + Attributes: + mid (str): + Object ID that should align with + EntityAnnotation mid. + 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. + name (str): + Object name, expressed in its ``language_code`` language. + score (float): + Score of the result. Range [0, 1]. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + name = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + + class GroupedResult(proto.Message): + r"""Information about the products similar to a single product in + a query image. + + Attributes: + bounding_poly (google.cloud.vision_v1.types.BoundingPoly): + The bounding polygon around the product + detected in the query image. + results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.Result]): + List of results, one for each product match. + object_annotations (Sequence[google.cloud.vision_v1.types.ProductSearchResults.ObjectAnnotation]): + List of generic predictions for the object in + the bounding box. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + results = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='ProductSearchResults.Result', + ) + object_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='ProductSearchResults.ObjectAnnotation', + ) + + index_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + results = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Result, + ) + product_grouped_results = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=GroupedResult, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py new file mode 100644 index 00000000..a7f76aa0 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py @@ -0,0 +1,1075 @@ +# -*- 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.vision_v1.types import geometry +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1', + manifest={ + 'Product', + 'ProductSet', + 'ReferenceImage', + 'CreateProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'GetProductRequest', + 'UpdateProductRequest', + 'DeleteProductRequest', + 'CreateProductSetRequest', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'GetProductSetRequest', + 'UpdateProductSetRequest', + 'DeleteProductSetRequest', + 'CreateReferenceImageRequest', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'GetReferenceImageRequest', + 'DeleteReferenceImageRequest', + 'AddProductToProductSetRequest', + 'RemoveProductFromProductSetRequest', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'BatchOperationMetadata', + 'ProductSetPurgeConfig', + 'PurgeProductsRequest', + }, +) + + +class Product(proto.Message): + r"""A Product contains ReferenceImages. + + Attributes: + name (str): + The resource name of the product. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This field is ignored when creating a product. + display_name (str): + The user-provided name for this Product. Must + not be empty. Must be at most 4096 characters + long. + description (str): + User-provided metadata to be stored with this + product. Must be at most 4096 characters long. + product_category (str): + Immutable. The category for the product + identified by the reference image. This should + be one of "homegoods-v2", "apparel-v2", + "toys-v2", "packagedgoods-v1" or "general-v1". + The legacy categories "homegoods", "apparel", + and "toys" are still supported, but these should + not be used for new products. + product_labels (Sequence[google.cloud.vision_v1.types.Product.KeyValue]): + Key-value pairs that can be attached to a product. At query + time, constraints can be specified based on the + product_labels. + + Note that integer values can be provided as strings, e.g. + "1199". Only strings with integer values can match a + range-based restriction which is to be supported soon. + + Multiple values can be assigned to the same key. One product + may have up to 500 product_labels. + + Notice that the total number of distinct product_labels over + all products in one ProductSet cannot exceed 1M, otherwise + the product search pipeline will refuse to work for that + ProductSet. + """ + + class KeyValue(proto.Message): + r"""A product label represented as a key-value pair. + + Attributes: + key (str): + The key of the label attached to the product. + Cannot be empty and cannot exceed 128 bytes. + value (str): + The value of the label attached to the + product. Cannot be empty and cannot exceed 128 + bytes. + """ + + key = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + product_category = proto.Field( + proto.STRING, + number=4, + ) + product_labels = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=KeyValue, + ) + + +class ProductSet(proto.Message): + r"""A ProductSet contains Products. A ProductSet can contain a + maximum of 1 million reference images. If the limit is exceeded, + periodic indexing will fail. + + Attributes: + name (str): + The resource name of the ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. + + This field is ignored when creating a ProductSet. + display_name (str): + The user-provided name for this ProductSet. + Must not be empty. Must be at most 4096 + characters long. + index_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which this + ProductSet was last indexed. Query results will + reflect all updates before this time. If this + ProductSet has never been indexed, this + timestamp is the default value + "1970-01-01T00:00:00Z". + + This field is ignored when creating a + ProductSet. + index_error (google.rpc.status_pb2.Status): + Output only. If there was an error with + indexing the product set, the field is + populated. + This field is ignored when creating a + ProductSet. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + index_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + index_error = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + + +class ReferenceImage(proto.Message): + r"""A ``ReferenceImage`` represents a product image and its associated + metadata, such as bounding boxes. + + Attributes: + name (str): + The resource name of the reference image. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + This field is ignored when creating a reference image. + uri (str): + Required. The Google Cloud Storage URI of the reference + image. + + The URI must start with ``gs://``. + bounding_polys (Sequence[google.cloud.vision_v1.types.BoundingPoly]): + Optional. Bounding polygons around the areas + of interest in the reference image. If this + field is empty, the system will try to detect + regions of interest. At most 10 bounding + polygons will be used. + The provided shape is converted into a non- + rotated rectangle. Once converted, the small + edge of the rectangle must be greater than or + equal to 300 pixels. The aspect ratio must be + 1:4 or less (i.e. 1:3 is ok; 1:5 is not). + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + uri = proto.Field( + proto.STRING, + number=2, + ) + bounding_polys = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, + ) + + +class CreateProductRequest(proto.Message): + r"""Request message for the ``CreateProduct`` method. + + Attributes: + parent (str): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + product (google.cloud.vision_v1.types.Product): + Required. The product to create. + product_id (str): + A user-supplied resource id for this Product. If set, the + server will attempt to use this value as the resource id. If + it is already in use, an error is returned with code + ALREADY_EXISTS. Must be at most 128 characters long. It + cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.MESSAGE, + number=2, + message='Product', + ) + product_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsRequest(proto.Message): + r"""Request message for the ``ListProducts`` method. + + Attributes: + parent (str): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsResponse(proto.Message): + r"""Response message for the ``ListProducts`` method. + + Attributes: + products (Sequence[google.cloud.vision_v1.types.Product]): + List of products. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + products = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetProductRequest(proto.Message): + r"""Request message for the ``GetProduct`` method. + + Attributes: + name (str): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateProductRequest(proto.Message): + r"""Request message for the ``UpdateProduct`` method. + + Attributes: + product (google.cloud.vision_v1.types.Product): + Required. The Product resource which replaces + the one on the server. product.name is + immutable. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that specifies + which fields to update. If update_mask isn't specified, all + mutable fields are to be updated. Valid mask paths include + ``product_labels``, ``display_name``, and ``description``. + """ + + product = proto.Field( + proto.MESSAGE, + number=1, + message='Product', + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteProductRequest(proto.Message): + r"""Request message for the ``DeleteProduct`` method. + + Attributes: + name (str): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateProductSetRequest(proto.Message): + r"""Request message for the ``CreateProductSet`` method. + + Attributes: + parent (str): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + product_set (google.cloud.vision_v1.types.ProductSet): + Required. The ProductSet to create. + product_set_id (str): + A user-supplied resource id for this ProductSet. If set, the + server will attempt to use this value as the resource id. If + it is already in use, an error is returned with code + ALREADY_EXISTS. Must be at most 128 characters long. It + cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + product_set = proto.Field( + proto.MESSAGE, + number=2, + message='ProductSet', + ) + product_set_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductSetsRequest(proto.Message): + r"""Request message for the ``ListProductSets`` method. + + Attributes: + parent (str): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductSetsResponse(proto.Message): + r"""Response message for the ``ListProductSets`` method. + + Attributes: + product_sets (Sequence[google.cloud.vision_v1.types.ProductSet]): + List of ProductSets. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + product_sets = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ProductSet', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetProductSetRequest(proto.Message): + r"""Request message for the ``GetProductSet`` method. + + Attributes: + name (str): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateProductSetRequest(proto.Message): + r"""Request message for the ``UpdateProductSet`` method. + + Attributes: + product_set (google.cloud.vision_v1.types.ProductSet): + Required. The ProductSet resource which + replaces the one on the server. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that specifies + which fields to update. If update_mask isn't specified, all + mutable fields are to be updated. Valid mask path is + ``display_name``. + """ + + product_set = proto.Field( + proto.MESSAGE, + number=1, + message='ProductSet', + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteProductSetRequest(proto.Message): + r"""Request message for the ``DeleteProductSet`` method. + + Attributes: + name (str): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateReferenceImageRequest(proto.Message): + r"""Request message for the ``CreateReferenceImage`` method. + + Attributes: + parent (str): + Required. Resource name of the product in which to create + the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + reference_image (google.cloud.vision_v1.types.ReferenceImage): + Required. The reference image to create. + If an image ID is specified, it is ignored. + reference_image_id (str): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value as + the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + reference_image = proto.Field( + proto.MESSAGE, + number=2, + message='ReferenceImage', + ) + reference_image_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListReferenceImagesRequest(proto.Message): + r"""Request message for the ``ListReferenceImages`` method. + + Attributes: + parent (str): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + A token identifying a page of results to be returned. This + is the value of ``nextPageToken`` returned in a previous + reference image list request. + + Defaults to the first page if not specified. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListReferenceImagesResponse(proto.Message): + r"""Response message for the ``ListReferenceImages`` method. + + Attributes: + reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): + The list of reference images. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + next_page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + @property + def raw_page(self): + return self + + reference_images = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ReferenceImage', + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + next_page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class GetReferenceImageRequest(proto.Message): + r"""Request message for the ``GetReferenceImage`` method. + + Attributes: + name (str): + Required. The resource name of the ReferenceImage to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteReferenceImageRequest(proto.Message): + r"""Request message for the ``DeleteReferenceImage`` method. + + Attributes: + name (str): + Required. The resource name of the reference image to + delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class AddProductToProductSetRequest(proto.Message): + r"""Request message for the ``AddProductToProductSet`` method. + + Attributes: + name (str): + Required. The resource name for the ProductSet to modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + product (str): + Required. The resource name for the Product to be added to + this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.STRING, + number=2, + ) + + +class RemoveProductFromProductSetRequest(proto.Message): + r"""Request message for the ``RemoveProductFromProductSet`` method. + + Attributes: + name (str): + Required. The resource name for the ProductSet to modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + product (str): + Required. The resource name for the Product to be removed + from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.STRING, + number=2, + ) + + +class ListProductsInProductSetRequest(proto.Message): + r"""Request message for the ``ListProductsInProductSet`` method. + + Attributes: + name (str): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsInProductSetResponse(proto.Message): + r"""Response message for the ``ListProductsInProductSet`` method. + + Attributes: + products (Sequence[google.cloud.vision_v1.types.Product]): + The list of Products. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + products = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class ImportProductSetsGcsSource(proto.Message): + r"""The Google Cloud Storage location for a csv file which + preserves a list of ImportProductSetRequests in each line. + + Attributes: + csv_file_uri (str): + The Google Cloud Storage URI of the input csv file. + + The URI must start with ``gs://``. + + The format of the input csv file should be one image per + line. In each line, there are 8 columns. + + 1. image-uri + 2. image-id + 3. product-set-id + 4. product-id + 5. product-category + 6. product-display-name + 7. labels + 8. bounding-poly + + The ``image-uri``, ``product-set-id``, ``product-id``, and + ``product-category`` columns are required. All other columns + are optional. + + If the ``ProductSet`` or ``Product`` specified by the + ``product-set-id`` and ``product-id`` values does not exist, + then the system will create a new ``ProductSet`` or + ``Product`` for the image. In this case, the + ``product-display-name`` column refers to + [display_name][google.cloud.vision.v1.Product.display_name], + the ``product-category`` column refers to + [product_category][google.cloud.vision.v1.Product.product_category], + and the ``labels`` column refers to + [product_labels][google.cloud.vision.v1.Product.product_labels]. + + The ``image-id`` column is optional but must be unique if + provided. If it is empty, the system will automatically + assign a unique id to the image. + + The ``product-display-name`` column is optional. If it is + empty, the system sets the + [display_name][google.cloud.vision.v1.Product.display_name] + field for the product to a space (" "). You can update the + ``display_name`` later by using the API. + + If a ``Product`` with the specified ``product-id`` already + exists, then the system ignores the + ``product-display-name``, ``product-category``, and + ``labels`` columns. + + The ``labels`` column (optional) is a line containing a list + of comma-separated key-value pairs, in the following format: + + :: + + "key_1=value_1,key_2=value_2,...,key_n=value_n" + + The ``bounding-poly`` column (optional) identifies one + region of interest from the image in the same manner as + ``CreateReferenceImage``. If you do not specify the + ``bounding-poly`` column, then the system will try to detect + regions of interest automatically. + + At most one ``bounding-poly`` column is allowed per line. If + the image contains multiple regions of interest, add a line + to the CSV file that includes the same product information, + and the ``bounding-poly`` values for each region of + interest. + + The ``bounding-poly`` column must contain an even number of + comma-separated numbers, in the format + "p1_x,p1_y,p2_x,p2_y,...,pn_x,pn_y". Use non-negative + integers for absolute bounding polygons, and float values in + [0, 1] for normalized bounding polygons. + + The system will resize the image if the image resolution is + too large to process (larger than 20MP). + """ + + csv_file_uri = proto.Field( + proto.STRING, + number=1, + ) + + +class ImportProductSetsInputConfig(proto.Message): + r"""The input content for the ``ImportProductSets`` method. + + Attributes: + gcs_source (google.cloud.vision_v1.types.ImportProductSetsGcsSource): + The Google Cloud Storage location for a csv + file which preserves a list of + ImportProductSetRequests in each line. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + oneof='source', + message='ImportProductSetsGcsSource', + ) + + +class ImportProductSetsRequest(proto.Message): + r"""Request message for the ``ImportProductSets`` method. + + Attributes: + parent (str): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + input_config (google.cloud.vision_v1.types.ImportProductSetsInputConfig): + Required. The input content for the list of + requests. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + input_config = proto.Field( + proto.MESSAGE, + number=2, + message='ImportProductSetsInputConfig', + ) + + +class ImportProductSetsResponse(proto.Message): + r"""Response message for the ``ImportProductSets`` method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + Attributes: + reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): + The list of reference_images that are imported successfully. + statuses (Sequence[google.rpc.status_pb2.Status]): + The rpc status for each ImportProductSet request, including + both successes and errors. + + The number of statuses here matches the number of lines in + the csv file, and statuses[i] stores the success or failure + status of processing the i-th line of the csv, starting from + line 0. + """ + + reference_images = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ReferenceImage', + ) + statuses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + + +class BatchOperationMetadata(proto.Message): + r"""Metadata for the batch operations such as the current state. + + This is included in the ``metadata`` field of the ``Operation`` + returned by the ``GetOperation`` call of the + ``google::longrunning::Operations`` service. + + Attributes: + state (google.cloud.vision_v1.types.BatchOperationMetadata.State): + The current state of the batch operation. + submit_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was submitted + to the server. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request is finished and + [google.longrunning.Operation.done][google.longrunning.Operation.done] + is set to true. + """ + class State(proto.Enum): + r"""Enumerates the possible states that the batch request can be + in. + """ + STATE_UNSPECIFIED = 0 + PROCESSING = 1 + SUCCESSFUL = 2 + FAILED = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + submit_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +class ProductSetPurgeConfig(proto.Message): + r"""Config to control which ProductSet contains the Products to + be deleted. + + Attributes: + product_set_id (str): + The ProductSet that contains the Products to delete. If a + Product is a member of product_set_id in addition to other + ProductSets, the Product will still be deleted. + """ + + product_set_id = proto.Field( + proto.STRING, + number=1, + ) + + +class PurgeProductsRequest(proto.Message): + r"""Request message for the ``PurgeProducts`` method. + + Attributes: + product_set_purge_config (google.cloud.vision_v1.types.ProductSetPurgeConfig): + Specify which ProductSet contains the + Products to be deleted. + delete_orphan_products (bool): + If delete_orphan_products is true, all Products that are not + in any ProductSet will be deleted. + parent (str): + Required. The project and location in which the Products + should be deleted. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + force (bool): + The default value is false. Override this + value to true to actually perform the purge. + """ + + product_set_purge_config = proto.Field( + proto.MESSAGE, + number=2, + oneof='target', + message='ProductSetPurgeConfig', + ) + delete_orphan_products = proto.Field( + proto.BOOL, + number=3, + oneof='target', + ) + parent = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py new file mode 100644 index 00000000..4b0d8b6e --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py @@ -0,0 +1,393 @@ +# -*- 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.vision_v1.types import geometry + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1', + manifest={ + 'TextAnnotation', + 'Page', + 'Block', + 'Paragraph', + 'Word', + 'Symbol', + }, +) + + +class TextAnnotation(proto.Message): + r"""TextAnnotation contains a structured representation of OCR extracted + text. The hierarchy of an OCR extracted text structure is like this: + TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each + structural component, starting from Page, may further have their own + properties. Properties describe detected languages, breaks etc.. + Please refer to the + [TextAnnotation.TextProperty][google.cloud.vision.v1.TextAnnotation.TextProperty] + message definition below for more detail. + + Attributes: + pages (Sequence[google.cloud.vision_v1.types.Page]): + List of pages detected by OCR. + text (str): + UTF-8 text detected on the pages. + """ + + 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, + ) + + class DetectedBreak(proto.Message): + r"""Detected start or end of a structural component. + + Attributes: + type_ (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak.BreakType): + Detected break type. + is_prefix (bool): + True if break prepends the element. + """ + class BreakType(proto.Enum): + r"""Enum to denote the type of break found. New line, space etc.""" + UNKNOWN = 0 + SPACE = 1 + SURE_SPACE = 2 + EOL_SURE_SPACE = 3 + HYPHEN = 4 + LINE_BREAK = 5 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='TextAnnotation.DetectedBreak.BreakType', + ) + is_prefix = proto.Field( + proto.BOOL, + number=2, + ) + + class TextProperty(proto.Message): + r"""Additional information detected on the structural component. + + Attributes: + detected_languages (Sequence[google.cloud.vision_v1.types.TextAnnotation.DetectedLanguage]): + A list of detected languages together with + confidence. + detected_break (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak): + Detected start or end of a text segment. + """ + + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='TextAnnotation.DetectedLanguage', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='TextAnnotation.DetectedBreak', + ) + + pages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Page', + ) + text = proto.Field( + proto.STRING, + number=2, + ) + + +class Page(proto.Message): + r"""Detected page from OCR. + + Attributes: + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): + Additional information detected on the page. + width (int): + Page width. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + height (int): + Page height. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + blocks (Sequence[google.cloud.vision_v1.types.Block]): + List of blocks of text, images etc on this + page. + confidence (float): + Confidence of the OCR results on the page. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + width = proto.Field( + proto.INT32, + number=2, + ) + height = proto.Field( + proto.INT32, + number=3, + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Block', + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Block(proto.Message): + r"""Logical element on the page. + + Attributes: + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): + Additional information detected for the + block. + bounding_box (google.cloud.vision_v1.types.BoundingPoly): + The bounding box for the block. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: + + :: + + 0----1 + | | + 3----2 + + - when it's rotated 180 degrees around the top-left corner + it becomes: + + :: + + 2----3 + | | + 1----0 + + and the vertex order will still be (0, 1, 2, 3). + paragraphs (Sequence[google.cloud.vision_v1.types.Paragraph]): + List of paragraphs in this block (if this + blocks is of type text). + block_type (google.cloud.vision_v1.types.Block.BlockType): + Detected block type (text, image etc) for + this block. + confidence (float): + Confidence of the OCR results on the block. Range [0, 1]. + """ + class BlockType(proto.Enum): + r"""Type of a block (text, image etc) as identified by OCR.""" + UNKNOWN = 0 + TEXT = 1 + TABLE = 2 + PICTURE = 3 + RULER = 4 + BARCODE = 5 + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Paragraph', + ) + block_type = proto.Field( + proto.ENUM, + number=4, + enum=BlockType, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Paragraph(proto.Message): + r"""Structural unit of text representing a number of words in + certain order. + + Attributes: + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): + Additional information detected for the + paragraph. + bounding_box (google.cloud.vision_v1.types.BoundingPoly): + The bounding box for the paragraph. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). + words (Sequence[google.cloud.vision_v1.types.Word]): + List of all words in this paragraph. + confidence (float): + Confidence of the OCR results for the paragraph. Range [0, + 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + words = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Word', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Word(proto.Message): + r"""A word representation. + + Attributes: + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): + Additional information detected for the word. + bounding_box (google.cloud.vision_v1.types.BoundingPoly): + The bounding box for the word. The vertices are in the order + of top-left, top-right, bottom-right, bottom-left. When a + rotation of the bounding box is detected the rotation is + represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). + symbols (Sequence[google.cloud.vision_v1.types.Symbol]): + List of symbols in the word. + The order of the symbols follows the natural + reading order. + confidence (float): + Confidence of the OCR results for the word. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + symbols = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Symbol', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Symbol(proto.Message): + r"""A single symbol representation. + + Attributes: + property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): + Additional information detected for the + symbol. + bounding_box (google.cloud.vision_v1.types.BoundingPoly): + The bounding box for the symbol. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). + text (str): + The actual UTF-8 representation of the + symbol. + confidence (float): + Confidence of the OCR results for the symbol. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + text = proto.Field( + proto.STRING, + number=3, + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.py new file mode 100644 index 00000000..1aa0be69 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.py @@ -0,0 +1,201 @@ +# -*- 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.vision.v1', + manifest={ + 'WebDetection', + }, +) + + +class WebDetection(proto.Message): + r"""Relevant information for the image from the Internet. + + Attributes: + web_entities (Sequence[google.cloud.vision_v1.types.WebDetection.WebEntity]): + Deduced entities from similar images on the + Internet. + full_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): + Fully matching images from the Internet. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): + Partial matching images from the Internet. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + pages_with_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebPage]): + Web pages containing the matching images from + the Internet. + visually_similar_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): + The visually similar image results. + best_guess_labels (Sequence[google.cloud.vision_v1.types.WebDetection.WebLabel]): + The service's best guess as to the topic of + the request image. Inferred from similar images + on the open web. + """ + + class WebEntity(proto.Message): + r"""Entity deduced from similar images on the Internet. + + Attributes: + entity_id (str): + Opaque entity ID. + score (float): + Overall relevancy score for the entity. + Not normalized and not comparable across + different image queries. + description (str): + Canonical description of the entity, in + English. + """ + + entity_id = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + + class WebImage(proto.Message): + r"""Metadata for online images. + + Attributes: + url (str): + The result image URL. + score (float): + (Deprecated) Overall relevancy score for the + image. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + + class WebPage(proto.Message): + r"""Metadata for web pages. + + Attributes: + url (str): + The result web page URL. + score (float): + (Deprecated) Overall relevancy score for the + web page. + page_title (str): + Title for the web page, may contain HTML + markups. + full_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): + Fully matching images on the page. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): + Partial matching images on the page. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + page_title = proto.Field( + proto.STRING, + number=3, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='WebDetection.WebImage', + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='WebDetection.WebImage', + ) + + class WebLabel(proto.Message): + r"""Label to provide extra metadata for the web detection. + + Attributes: + label (str): + Label for extra metadata. + language_code (str): + The BCP-47 language code for ``label``, such as "en-US" or + "sr-Latn". For more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + """ + + label = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + + web_entities = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=WebEntity, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=WebImage, + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=WebImage, + ) + pages_with_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=WebPage, + ) + visually_similar_images = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=WebImage, + ) + best_guess_labels = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=WebLabel, + ) + + +__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..18bc9985 --- /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/vision_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_vision_v1_keywords.py b/owl-bot-staging/v1/scripts/fixup_vision_v1_keywords.py new file mode 100644 index 00000000..a4842deb --- /dev/null +++ b/owl-bot-staging/v1/scripts/fixup_vision_v1_keywords.py @@ -0,0 +1,198 @@ +#! /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 visionCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'add_product_to_product_set': ('name', 'product', ), + 'async_batch_annotate_files': ('requests', 'parent', ), + 'async_batch_annotate_images': ('requests', 'output_config', 'parent', ), + 'batch_annotate_files': ('requests', 'parent', ), + 'batch_annotate_images': ('requests', 'parent', ), + 'create_product': ('parent', 'product', 'product_id', ), + 'create_product_set': ('parent', 'product_set', 'product_set_id', ), + 'create_reference_image': ('parent', 'reference_image', 'reference_image_id', ), + 'delete_product': ('name', ), + 'delete_product_set': ('name', ), + 'delete_reference_image': ('name', ), + 'get_product': ('name', ), + 'get_product_set': ('name', ), + 'get_reference_image': ('name', ), + 'import_product_sets': ('parent', 'input_config', ), + 'list_products': ('parent', 'page_size', 'page_token', ), + 'list_product_sets': ('parent', 'page_size', 'page_token', ), + 'list_products_in_product_set': ('name', 'page_size', 'page_token', ), + 'list_reference_images': ('parent', 'page_size', 'page_token', ), + 'purge_products': ('parent', 'product_set_purge_config', 'delete_orphan_products', 'force', ), + 'remove_product_from_product_set': ('name', 'product', ), + 'update_product': ('product', 'update_mask', ), + 'update_product_set': ('product_set', 'update_mask', ), + } + + 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: a.keyword.value not 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=visionCallTransformer(), +): + """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 vision 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..9d03e702 --- /dev/null +++ b/owl-bot-staging/v1/setup.py @@ -0,0 +1,54 @@ +# -*- 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-vision', + 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, < 3.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', + 'Programming Language :: Python :: 3.9', + '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/vision_v1/__init__.py b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/gapic/vision_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/vision_v1/test_image_annotator.py b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_image_annotator.py new file mode 100644 index 00000000..f4c55cf2 --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_image_annotator.py @@ -0,0 +1,1723 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorAsyncClient +from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorClient +from google.cloud.vision_v1.services.image_annotator import transports +from google.cloud.vision_v1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1.types import geometry +from google.cloud.vision_v1.types import image_annotator +from google.cloud.vision_v1.types import product_search +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ImageAnnotatorGrpcTransport, "grpc"), + (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +def test_image_annotator_client_get_transport_class(): + transport = ImageAnnotatorClient.get_transport_class() + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports + + transport = ImageAnnotatorClient.get_transport_class("grpc") + assert transport == transports.ImageAnnotatorGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + +def test_image_annotator_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ImageAnnotatorClient( + 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, + always_use_jwt_access=True, + ) + + +def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse( + ) + response = client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +def test_batch_annotate_images_from_dict(): + test_batch_annotate_images(request_type=dict) + + +def test_batch_annotate_images_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 = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + client.batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( + )) + response = await client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async_from_dict(): + await test_batch_annotate_images_async(request_type=dict) + + +def test_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +def test_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +def test_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateFilesRequest): + client = ImageAnnotatorClient( + 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_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateFilesResponse( + ) + response = client.batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) + + +def test_batch_annotate_files_from_dict(): + test_batch_annotate_files(request_type=dict) + + +def test_batch_annotate_files_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 = ImageAnnotatorClient( + 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_annotate_files), + '__call__') as call: + client.batch_annotate_files() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateFilesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateFilesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse( + )) + response = await client.batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_files_async_from_dict(): + await test_batch_annotate_files_async(request_type=dict) + + +def test_batch_annotate_files_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateFilesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_files( + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +def test_batch_annotate_files_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_files( + image_annotator.BatchAnnotateFilesRequest(), + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_files_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateFilesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_files( + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +@pytest.mark.asyncio +async def test_batch_annotate_files_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_files( + image_annotator.BatchAnnotateFilesRequest(), + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +def test_async_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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.async_batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.async_batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_async_batch_annotate_images_from_dict(): + test_async_batch_annotate_images(request_type=dict) + + +def test_async_batch_annotate_images_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 = ImageAnnotatorClient( + 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.async_batch_annotate_images), + '__call__') as call: + client.async_batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_images), + '__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.async_batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_async_from_dict(): + await test_async_batch_annotate_images_async(request_type=dict) + + +def test_async_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_images), + '__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.async_batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) + + +def test_async_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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.async_batch_annotate_images( + image_annotator.AsyncBatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), + ) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_images), + '__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.async_batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_images( + image_annotator.AsyncBatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), + ) + + +def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_async_batch_annotate_files_from_dict(): + test_async_batch_annotate_files(request_type=dict) + + +def test_async_batch_annotate_files_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 = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + client.async_batch_annotate_files() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files), + '__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.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async_from_dict(): + await test_async_batch_annotate_files_async(request_type=dict) + + +def test_async_batch_annotate_files_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +def test_async_batch_annotate_files_flattened_error(): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ImageAnnotatorClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, +]) +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 = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ImageAnnotatorGrpcTransport, + ) + +def test_image_annotator_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_image_annotator_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'batch_annotate_images', + 'batch_annotate_files', + 'async_batch_annotate_images', + 'async_batch_annotate_files', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ImageAnnotatorGrpcTransport, grpc_helpers), + (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_image_annotator_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_host_no_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_image_annotator_host_with_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_image_annotator_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcTransport( + 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_image_annotator_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_grpc_lro_client(): + client = ImageAnnotatorClient( + 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_image_annotator_grpc_lro_async_client(): + client = ImageAnnotatorAsyncClient( + 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_product_path(): + project = "squid" + location = "clam" + product = "whelk" + expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + actual = ImageAnnotatorClient.product_path(project, location, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "project": "octopus", + "location": "oyster", + "product": "nudibranch", + } + path = ImageAnnotatorClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_product_path(path) + assert expected == actual + +def test_product_set_path(): + project = "cuttlefish" + location = "mussel" + product_set = "winkle" + expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + actual = ImageAnnotatorClient.product_set_path(project, location, product_set) + assert expected == actual + + +def test_parse_product_set_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "product_set": "abalone", + } + path = ImageAnnotatorClient.product_set_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_product_set_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ImageAnnotatorClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ImageAnnotatorClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = ImageAnnotatorClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ImageAnnotatorClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ImageAnnotatorClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ImageAnnotatorClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = ImageAnnotatorClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ImageAnnotatorClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ImageAnnotatorClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + transport_class = ImageAnnotatorClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py new file mode 100644 index 00000000..3d3b6976 --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py @@ -0,0 +1,6323 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1.services.product_search import ProductSearchAsyncClient +from google.cloud.vision_v1.services.product_search import ProductSearchClient +from google.cloud.vision_v1.services.product_search import pagers +from google.cloud.vision_v1.services.product_search import transports +from google.cloud.vision_v1.services.product_search.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1.types import geometry +from google.cloud.vision_v1.types import product_search_service +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +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 ProductSearchClient._get_default_mtls_endpoint(None) is None + assert ProductSearchClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ProductSearchClient, + ProductSearchAsyncClient, +]) +def test_product_search_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductSearchGrpcTransport, "grpc"), + (transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ProductSearchClient, + ProductSearchAsyncClient, +]) +def test_product_search_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 == 'vision.googleapis.com:443' + + +def test_product_search_client_get_transport_class(): + transport = ProductSearchClient.get_transport_class() + available_transports = [ + transports.ProductSearchGrpcTransport, + ] + assert transport in available_transports + + transport = ProductSearchClient.get_transport_class("grpc") + assert transport == transports.ProductSearchGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) +@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) +def test_product_search_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(ProductSearchClient, '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(ProductSearchClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "true"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "false"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) +@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_product_search_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_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, + always_use_jwt_access=True, + ) + + +def test_product_search_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1.services.product_search.transports.ProductSearchGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductSearchClient( + 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, + always_use_jwt_access=True, + ) + + +def test_create_product_set(transport: str = 'grpc', request_type=product_search_service.CreateProductSetRequest): + client = ProductSearchClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.create_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_create_product_set_from_dict(): + test_create_product_set(request_type=dict) + + +def test_create_product_set_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 = ProductSearchClient( + 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_product_set), + '__call__') as call: + client.create_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + +@pytest.mark.asyncio +async def test_create_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductSetRequest): + client = ProductSearchAsyncClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.create_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_create_product_set_async_from_dict(): + await test_create_product_set_async(request_type=dict) + + +def test_create_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateProductSetRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.create_product_set(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_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateProductSetRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.create_product_set(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_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_product_set( + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].product_set_id == 'product_set_id_value' + + +def test_create_product_set_flattened_error(): + client = ProductSearchClient( + 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_product_set( + product_search_service.CreateProductSetRequest(), + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_product_set( + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].product_set_id == 'product_set_id_value' + + +@pytest.mark.asyncio +async def test_create_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_set( + product_search_service.CreateProductSetRequest(), + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_value', + ) + + +def test_list_product_sets(transport: str = 'grpc', request_type=product_search_service.ListProductSetsRequest): + client = ProductSearchClient( + 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_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductSetsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_product_sets_from_dict(): + test_list_product_sets(request_type=dict) + + +def test_list_product_sets_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 = ProductSearchClient( + 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_product_sets), + '__call__') as call: + client.list_product_sets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + +@pytest.mark.asyncio +async def test_list_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductSetsRequest): + client = ProductSearchAsyncClient( + 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_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductSetsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_product_sets_async_from_dict(): + await test_list_product_sets_async(request_type=dict) + + +def test_list_product_sets_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + call.return_value = product_search_service.ListProductSetsResponse() + client.list_product_sets(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_product_sets_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) + await client.list_product_sets(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_product_sets_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_product_sets( + 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_product_sets_flattened_error(): + client = ProductSearchClient( + 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_product_sets( + product_search_service.ListProductSetsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_product_sets_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_product_sets( + 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_product_sets_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_sets( + product_search_service.ListProductSetsRequest(), + parent='parent_value', + ) + + +def test_list_product_sets_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_product_sets(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.ProductSet) + for i in results) + +def test_list_product_sets_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + pages = list(client.list_product_sets(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_product_sets_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_product_sets(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, product_search_service.ProductSet) + for i in responses) + +@pytest.mark.asyncio +async def test_list_product_sets_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_product_sets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_product_set(transport: str = 'grpc', request_type=product_search_service.GetProductSetRequest): + client = ProductSearchClient( + 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.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.get_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_get_product_set_from_dict(): + test_get_product_set(request_type=dict) + + +def test_get_product_set_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 = ProductSearchClient( + 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.get_product_set), + '__call__') as call: + client.get_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + +@pytest.mark.asyncio +async def test_get_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductSetRequest): + client = ProductSearchAsyncClient( + 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.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.get_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_get_product_set_async_from_dict(): + await test_get_product_set_async(request_type=dict) + + +def test_get_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.get_product_set(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_get_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.get_product_set(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_get_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product_set( + 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_get_product_set_flattened_error(): + client = ProductSearchClient( + 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.get_product_set( + product_search_service.GetProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product_set( + 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_get_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_product_set( + product_search_service.GetProductSetRequest(), + name='name_value', + ) + + +def test_update_product_set(transport: str = 'grpc', request_type=product_search_service.UpdateProductSetRequest): + client = ProductSearchClient( + 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.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.update_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_update_product_set_from_dict(): + test_update_product_set(request_type=dict) + + +def test_update_product_set_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 = ProductSearchClient( + 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.update_product_set), + '__call__') as call: + client.update_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + +@pytest.mark.asyncio +async def test_update_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductSetRequest): + client = ProductSearchAsyncClient( + 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.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.update_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_update_product_set_async_from_dict(): + await test_update_product_set_async(request_type=dict) + + +def test_update_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.UpdateProductSetRequest() + + request.product_set.name = 'product_set.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.update_product_set(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', + 'product_set.name=product_set.name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.UpdateProductSetRequest() + + request.product_set.name = 'product_set.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.update_product_set(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', + 'product_set.name=product_set.name/value', + ) in kw['metadata'] + + +def test_update_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product_set( + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +def test_update_product_set_flattened_error(): + client = ProductSearchClient( + 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.update_product_set( + product_search_service.UpdateProductSetRequest(), + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.asyncio +async def test_update_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product_set( + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +@pytest.mark.asyncio +async def test_update_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.update_product_set( + product_search_service.UpdateProductSetRequest(), + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product_set(transport: str = 'grpc', request_type=product_search_service.DeleteProductSetRequest): + client = ProductSearchClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_set_from_dict(): + test_delete_product_set(request_type=dict) + + +def test_delete_product_set_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 = ProductSearchClient( + 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_product_set), + '__call__') as call: + client.delete_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + +@pytest.mark.asyncio +async def test_delete_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductSetRequest): + client = ProductSearchAsyncClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_set_async_from_dict(): + await test_delete_product_set_async(request_type=dict) + + +def test_delete_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + call.return_value = None + client.delete_product_set(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_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_set(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_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product_set( + 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_product_set_flattened_error(): + client = ProductSearchClient( + 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_product_set( + product_search_service.DeleteProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product_set( + 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_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_set( + product_search_service.DeleteProductSetRequest(), + name='name_value', + ) + + +def test_create_product(transport: str = 'grpc', request_type=product_search_service.CreateProductRequest): + client = ProductSearchClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.create_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_create_product_from_dict(): + test_create_product(request_type=dict) + + +def test_create_product_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 = ProductSearchClient( + 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_product), + '__call__') as call: + client.create_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + +@pytest.mark.asyncio +async def test_create_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductRequest): + client = ProductSearchAsyncClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.create_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_create_product_async_from_dict(): + await test_create_product_async(request_type=dict) + + +def test_create_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateProductRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.create_product(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_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateProductRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.create_product(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_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_product( + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_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].product == product_search_service.Product(name='name_value') + assert args[0].product_id == 'product_id_value' + + +def test_create_product_flattened_error(): + client = ProductSearchClient( + 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_product( + product_search_service.CreateProductRequest(), + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_product( + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_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].product == product_search_service.Product(name='name_value') + assert args[0].product_id == 'product_id_value' + + +@pytest.mark.asyncio +async def test_create_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product( + product_search_service.CreateProductRequest(), + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_value', + ) + + +def test_list_products(transport: str = 'grpc', request_type=product_search_service.ListProductsRequest): + client = ProductSearchClient( + 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_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_from_dict(): + test_list_products(request_type=dict) + + +def test_list_products_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 = ProductSearchClient( + 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_products), + '__call__') as call: + client.list_products() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + +@pytest.mark.asyncio +async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsRequest): + client = ProductSearchAsyncClient( + 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_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_async_from_dict(): + await test_list_products_async(request_type=dict) + + +def test_list_products_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = product_search_service.ListProductsResponse() + client.list_products(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_products_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) + await client.list_products(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_products_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products( + 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_products_flattened_error(): + client = ProductSearchClient( + 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_products( + product_search_service.ListProductsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_products_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products( + 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_products_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_products( + product_search_service.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_products(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.Product) + for i in results) + +def test_list_products_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products(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_products_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products(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, product_search_service.Product) + for i in responses) + +@pytest.mark.asyncio +async def test_list_products_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_products(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_product(transport: str = 'grpc', request_type=product_search_service.GetProductRequest): + client = ProductSearchClient( + 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.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_get_product_from_dict(): + test_get_product(request_type=dict) + + +def test_get_product_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 = ProductSearchClient( + 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.get_product), + '__call__') as call: + client.get_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + +@pytest.mark.asyncio +async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductRequest): + client = ProductSearchAsyncClient( + 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.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_get_product_async_from_dict(): + await test_get_product_async(request_type=dict) + + +def test_get_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.get_product(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_get_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.get_product(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_get_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product( + 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_get_product_flattened_error(): + client = ProductSearchClient( + 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.get_product( + product_search_service.GetProductRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product( + 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_get_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_product( + product_search_service.GetProductRequest(), + name='name_value', + ) + + +def test_update_product(transport: str = 'grpc', request_type=product_search_service.UpdateProductRequest): + client = ProductSearchClient( + 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.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.update_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_update_product_from_dict(): + test_update_product(request_type=dict) + + +def test_update_product_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 = ProductSearchClient( + 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.update_product), + '__call__') as call: + client.update_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + +@pytest.mark.asyncio +async def test_update_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductRequest): + client = ProductSearchAsyncClient( + 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.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.update_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_update_product_async_from_dict(): + await test_update_product_async(request_type=dict) + + +def test_update_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.UpdateProductRequest() + + request.product.name = 'product.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.update_product(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', + 'product.name=product.name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.UpdateProductRequest() + + request.product.name = 'product.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.update_product(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', + 'product.name=product.name/value', + ) in kw['metadata'] + + +def test_update_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product( + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +def test_update_product_flattened_error(): + client = ProductSearchClient( + 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.update_product( + product_search_service.UpdateProductRequest(), + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.asyncio +async def test_update_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product( + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +@pytest.mark.asyncio +async def test_update_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.update_product( + product_search_service.UpdateProductRequest(), + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product(transport: str = 'grpc', request_type=product_search_service.DeleteProductRequest): + client = ProductSearchClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_from_dict(): + test_delete_product(request_type=dict) + + +def test_delete_product_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 = ProductSearchClient( + 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_product), + '__call__') as call: + client.delete_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + +@pytest.mark.asyncio +async def test_delete_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductRequest): + client = ProductSearchAsyncClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_async_from_dict(): + await test_delete_product_async(request_type=dict) + + +def test_delete_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + call.return_value = None + client.delete_product(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_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product(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_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product( + 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_product_flattened_error(): + client = ProductSearchClient( + 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_product( + product_search_service.DeleteProductRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product( + 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_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product( + product_search_service.DeleteProductRequest(), + name='name_value', + ) + + +def test_create_reference_image(transport: str = 'grpc', request_type=product_search_service.CreateReferenceImageRequest): + client = ProductSearchClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + ) + response = client.create_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +def test_create_reference_image_from_dict(): + test_create_reference_image(request_type=dict) + + +def test_create_reference_image_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 = ProductSearchClient( + 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_reference_image), + '__call__') as call: + client.create_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_create_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateReferenceImageRequest): + client = ProductSearchAsyncClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + )) + response = await client.create_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +@pytest.mark.asyncio +async def test_create_reference_image_async_from_dict(): + await test_create_reference_image_async(request_type=dict) + + +def test_create_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateReferenceImageRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + call.return_value = product_search_service.ReferenceImage() + client.create_reference_image(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_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateReferenceImageRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + await client.create_reference_image(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_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_reference_image( + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') + assert args[0].reference_image_id == 'reference_image_id_value' + + +def test_create_reference_image_flattened_error(): + client = ProductSearchClient( + 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_reference_image( + product_search_service.CreateReferenceImageRequest(), + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_reference_image( + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') + assert args[0].reference_image_id == 'reference_image_id_value' + + +@pytest.mark.asyncio +async def test_create_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_image( + product_search_service.CreateReferenceImageRequest(), + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_value', + ) + + +def test_delete_reference_image(transport: str = 'grpc', request_type=product_search_service.DeleteReferenceImageRequest): + client = ProductSearchClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_reference_image_from_dict(): + test_delete_reference_image(request_type=dict) + + +def test_delete_reference_image_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 = ProductSearchClient( + 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_reference_image), + '__call__') as call: + client.delete_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_delete_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteReferenceImageRequest): + client = ProductSearchAsyncClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_reference_image_async_from_dict(): + await test_delete_reference_image_async(request_type=dict) + + +def test_delete_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + call.return_value = None + client.delete_reference_image(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_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_reference_image(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_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_reference_image( + 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_reference_image_flattened_error(): + client = ProductSearchClient( + 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_reference_image( + product_search_service.DeleteReferenceImageRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_reference_image( + 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_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_image( + product_search_service.DeleteReferenceImageRequest(), + name='name_value', + ) + + +def test_list_reference_images(transport: str = 'grpc', request_type=product_search_service.ListReferenceImagesRequest): + client = ProductSearchClient( + 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_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse( + page_size=951, + next_page_token='next_page_token_value', + ) + response = client.list_reference_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReferenceImagesPager) + assert response.page_size == 951 + assert response.next_page_token == 'next_page_token_value' + + +def test_list_reference_images_from_dict(): + test_list_reference_images(request_type=dict) + + +def test_list_reference_images_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 = ProductSearchClient( + 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_reference_images), + '__call__') as call: + client.list_reference_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + +@pytest.mark.asyncio +async def test_list_reference_images_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListReferenceImagesRequest): + client = ProductSearchAsyncClient( + 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_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse( + page_size=951, + next_page_token='next_page_token_value', + )) + response = await client.list_reference_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReferenceImagesAsyncPager) + assert response.page_size == 951 + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_reference_images_async_from_dict(): + await test_list_reference_images_async(request_type=dict) + + +def test_list_reference_images_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListReferenceImagesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + call.return_value = product_search_service.ListReferenceImagesResponse() + client.list_reference_images(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_reference_images_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListReferenceImagesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) + await client.list_reference_images(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_reference_images_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_reference_images( + 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_reference_images_flattened_error(): + client = ProductSearchClient( + 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_reference_images( + product_search_service.ListReferenceImagesRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_reference_images_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_reference_images( + 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_reference_images_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_images( + product_search_service.ListReferenceImagesRequest(), + parent='parent_value', + ) + + +def test_list_reference_images_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_reference_images(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.ReferenceImage) + for i in results) + +def test_list_reference_images_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + pages = list(client.list_reference_images(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_reference_images_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_reference_images(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, product_search_service.ReferenceImage) + for i in responses) + +@pytest.mark.asyncio +async def test_list_reference_images_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_reference_images(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_reference_image(transport: str = 'grpc', request_type=product_search_service.GetReferenceImageRequest): + client = ProductSearchClient( + 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.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + ) + response = client.get_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +def test_get_reference_image_from_dict(): + test_get_reference_image(request_type=dict) + + +def test_get_reference_image_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 = ProductSearchClient( + 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.get_reference_image), + '__call__') as call: + client.get_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_get_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetReferenceImageRequest): + client = ProductSearchAsyncClient( + 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.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + )) + response = await client.get_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +@pytest.mark.asyncio +async def test_get_reference_image_async_from_dict(): + await test_get_reference_image_async(request_type=dict) + + +def test_get_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + call.return_value = product_search_service.ReferenceImage() + client.get_reference_image(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_get_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + await client.get_reference_image(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_get_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_reference_image( + 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_get_reference_image_flattened_error(): + client = ProductSearchClient( + 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.get_reference_image( + product_search_service.GetReferenceImageRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_reference_image( + 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_get_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_reference_image( + product_search_service.GetReferenceImageRequest(), + name='name_value', + ) + + +def test_add_product_to_product_set(transport: str = 'grpc', request_type=product_search_service.AddProductToProductSetRequest): + client = ProductSearchClient( + 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.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.add_product_to_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_add_product_to_product_set_from_dict(): + test_add_product_to_product_set(request_type=dict) + + +def test_add_product_to_product_set_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 = ProductSearchClient( + 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.add_product_to_product_set), + '__call__') as call: + client.add_product_to_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.AddProductToProductSetRequest): + client = ProductSearchAsyncClient( + 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.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.add_product_to_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_async_from_dict(): + await test_add_product_to_product_set_async(request_type=dict) + + +def test_add_product_to_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.AddProductToProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + call.return_value = None + client.add_product_to_product_set(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_add_product_to_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.AddProductToProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.add_product_to_product_set(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_add_product_to_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_product_to_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +def test_add_product_to_product_set_flattened_error(): + client = ProductSearchClient( + 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.add_product_to_product_set( + product_search_service.AddProductToProductSetRequest(), + name='name_value', + product='product_value', + ) + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_product_to_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.add_product_to_product_set( + product_search_service.AddProductToProductSetRequest(), + name='name_value', + product='product_value', + ) + + +def test_remove_product_from_product_set(transport: str = 'grpc', request_type=product_search_service.RemoveProductFromProductSetRequest): + client = ProductSearchClient( + 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.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.remove_product_from_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_remove_product_from_product_set_from_dict(): + test_remove_product_from_product_set(request_type=dict) + + +def test_remove_product_from_product_set_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 = ProductSearchClient( + 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.remove_product_from_product_set), + '__call__') as call: + client.remove_product_from_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.RemoveProductFromProductSetRequest): + client = ProductSearchAsyncClient( + 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.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.remove_product_from_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_async_from_dict(): + await test_remove_product_from_product_set_async(request_type=dict) + + +def test_remove_product_from_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.RemoveProductFromProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + call.return_value = None + client.remove_product_from_product_set(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_remove_product_from_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.RemoveProductFromProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.remove_product_from_product_set(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_remove_product_from_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.remove_product_from_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +def test_remove_product_from_product_set_flattened_error(): + client = ProductSearchClient( + 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.remove_product_from_product_set( + product_search_service.RemoveProductFromProductSetRequest(), + name='name_value', + product='product_value', + ) + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.remove_product_from_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.remove_product_from_product_set( + product_search_service.RemoveProductFromProductSetRequest(), + name='name_value', + product='product_value', + ) + + +def test_list_products_in_product_set(transport: str = 'grpc', request_type=product_search_service.ListProductsInProductSetRequest): + client = ProductSearchClient( + 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_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products_in_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsInProductSetPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_in_product_set_from_dict(): + test_list_products_in_product_set(request_type=dict) + + +def test_list_products_in_product_set_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 = ProductSearchClient( + 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_products_in_product_set), + '__call__') as call: + client.list_products_in_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsInProductSetRequest): + client = ProductSearchAsyncClient( + 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_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products_in_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsInProductSetAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async_from_dict(): + await test_list_products_in_product_set_async(request_type=dict) + + +def test_list_products_in_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductsInProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + call.return_value = product_search_service.ListProductsInProductSetResponse() + client.list_products_in_product_set(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_list_products_in_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductsInProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) + await client.list_products_in_product_set(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_list_products_in_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products_in_product_set( + 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_list_products_in_product_set_flattened_error(): + client = ProductSearchClient( + 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_products_in_product_set( + product_search_service.ListProductsInProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products_in_product_set( + 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_list_products_in_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_products_in_product_set( + product_search_service.ListProductsInProductSetRequest(), + name='name_value', + ) + + +def test_list_products_in_product_set_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('name', ''), + )), + ) + pager = client.list_products_in_product_set(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.Product) + for i in results) + +def test_list_products_in_product_set_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products_in_product_set(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_products_in_product_set_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products_in_product_set(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, product_search_service.Product) + for i in responses) + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_products_in_product_set(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_import_product_sets(transport: str = 'grpc', request_type=product_search_service.ImportProductSetsRequest): + client = ProductSearchClient( + 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.import_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.import_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_import_product_sets_from_dict(): + test_import_product_sets(request_type=dict) + + +def test_import_product_sets_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 = ProductSearchClient( + 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.import_product_sets), + '__call__') as call: + client.import_product_sets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + +@pytest.mark.asyncio +async def test_import_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ImportProductSetsRequest): + client = ProductSearchAsyncClient( + 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.import_product_sets), + '__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.import_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_import_product_sets_async_from_dict(): + await test_import_product_sets_async(request_type=dict) + + +def test_import_product_sets_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ImportProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.import_product_sets(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_import_product_sets_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ImportProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.import_product_sets(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_import_product_sets_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__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.import_product_sets( + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) + + +def test_import_product_sets_flattened_error(): + client = ProductSearchClient( + 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.import_product_sets( + product_search_service.ImportProductSetsRequest(), + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), + ) + + +@pytest.mark.asyncio +async def test_import_product_sets_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__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.import_product_sets( + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) + + +@pytest.mark.asyncio +async def test_import_product_sets_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.import_product_sets( + product_search_service.ImportProductSetsRequest(), + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), + ) + + +def test_purge_products(transport: str = 'grpc', request_type=product_search_service.PurgeProductsRequest): + client = ProductSearchClient( + 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.purge_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.purge_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.PurgeProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_purge_products_from_dict(): + test_purge_products(request_type=dict) + + +def test_purge_products_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 = ProductSearchClient( + 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.purge_products), + '__call__') as call: + client.purge_products() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.PurgeProductsRequest() + + +@pytest.mark.asyncio +async def test_purge_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.PurgeProductsRequest): + client = ProductSearchAsyncClient( + 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.purge_products), + '__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.purge_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.PurgeProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_purge_products_async_from_dict(): + await test_purge_products_async(request_type=dict) + + +def test_purge_products_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.PurgeProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.purge_products(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_purge_products_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.PurgeProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.purge_products(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_purge_products_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__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.purge_products( + 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_purge_products_flattened_error(): + client = ProductSearchClient( + 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.purge_products( + product_search_service.PurgeProductsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_purge_products_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__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.purge_products( + 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_purge_products_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.purge_products( + product_search_service.PurgeProductsRequest(), + parent='parent_value', + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductSearchClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductSearchGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, +]) +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 = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductSearchGrpcTransport, + ) + +def test_product_search_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductSearchTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_product_search_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1.services.product_search.transports.ProductSearchTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductSearchTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'create_product_set', + 'list_product_sets', + 'get_product_set', + 'update_product_set', + 'delete_product_set', + 'create_product', + 'list_products', + 'get_product', + 'update_product', + 'delete_product', + 'create_reference_image', + 'delete_reference_image', + 'list_reference_images', + 'get_reference_image', + 'add_product_to_product_set', + 'remove_product_from_product_set', + 'list_products_in_product_set', + 'import_product_sets', + 'purge_products', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_product_search_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) + ProductSearchClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_product_search_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) + ProductSearchClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_product_search_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_product_search_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductSearchGrpcTransport, grpc_helpers), + (transports.ProductSearchGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_product_search_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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_product_search_host_no_port(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_product_search_host_with_port(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_product_search_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductSearchGrpcTransport( + 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_product_search_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductSearchGrpcAsyncIOTransport( + 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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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_product_search_grpc_lro_client(): + client = ProductSearchClient( + 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_product_search_grpc_lro_async_client(): + client = ProductSearchAsyncClient( + 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_product_path(): + project = "squid" + location = "clam" + product = "whelk" + expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + actual = ProductSearchClient.product_path(project, location, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "project": "octopus", + "location": "oyster", + "product": "nudibranch", + } + path = ProductSearchClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_product_path(path) + assert expected == actual + +def test_product_set_path(): + project = "cuttlefish" + location = "mussel" + product_set = "winkle" + expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + actual = ProductSearchClient.product_set_path(project, location, product_set) + assert expected == actual + + +def test_parse_product_set_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "product_set": "abalone", + } + path = ProductSearchClient.product_set_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_product_set_path(path) + assert expected == actual + +def test_reference_image_path(): + project = "squid" + location = "clam" + product = "whelk" + reference_image = "octopus" + expected = "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) + actual = ProductSearchClient.reference_image_path(project, location, product, reference_image) + assert expected == actual + + +def test_parse_reference_image_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "product": "cuttlefish", + "reference_image": "mussel", + } + path = ProductSearchClient.reference_image_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_reference_image_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductSearchClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = ProductSearchClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductSearchClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = ProductSearchClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductSearchClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = ProductSearchClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format(project=project, ) + actual = ProductSearchClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = ProductSearchClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductSearchClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = ProductSearchClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.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.ProductSearchTransport, '_prep_wrapped_messages') as prep: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductSearchTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductSearchClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1p1beta1/.coveragerc b/owl-bot-staging/v1p1beta1/.coveragerc new file mode 100644 index 00000000..75747063 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/vision/__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/v1p1beta1/MANIFEST.in b/owl-bot-staging/v1p1beta1/MANIFEST.in new file mode 100644 index 00000000..7fd81c6f --- /dev/null +++ b/owl-bot-staging/v1p1beta1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/vision *.py +recursive-include google/cloud/vision_v1p1beta1 *.py diff --git a/owl-bot-staging/v1p1beta1/README.rst b/owl-bot-staging/v1p1beta1/README.rst new file mode 100644 index 00000000..39f9ca72 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Vision 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 Vision 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/v1p1beta1/docs/conf.py b/owl-bot-staging/v1p1beta1/docs/conf.py new file mode 100644 index 00000000..6e730bf5 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/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-vision 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-vision" +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-vision-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-vision.tex", + u"google-cloud-vision 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-vision", + u"Google Cloud Vision 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-vision", + u"google-cloud-vision Documentation", + author, + "google-cloud-vision", + "GAPIC library for Google Cloud Vision 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/v1p1beta1/docs/index.rst b/owl-bot-staging/v1p1beta1/docs/index.rst new file mode 100644 index 00000000..049cf367 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + vision_v1p1beta1/services + vision_v1p1beta1/types diff --git a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst new file mode 100644 index 00000000..4aa9e5a2 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p1beta1.services.image_annotator + :members: + :inherited-members: diff --git a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst new file mode 100644 index 00000000..1b046a84 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Vision v1p1beta1 API +============================================== +.. toctree:: + :maxdepth: 2 + + image_annotator diff --git a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst new file mode 100644 index 00000000..11b2290f --- /dev/null +++ b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Vision v1p1beta1 API +=========================================== + +.. automodule:: google.cloud.vision_v1p1beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py new file mode 100644 index 00000000..efb3365d --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py @@ -0,0 +1,89 @@ +# -*- 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.vision_v1p1beta1.services.image_annotator.client import ImageAnnotatorClient +from google.cloud.vision_v1p1beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient + +from google.cloud.vision_v1p1beta1.types.geometry import BoundingPoly +from google.cloud.vision_v1p1beta1.types.geometry import Position +from google.cloud.vision_v1p1beta1.types.geometry import Vertex +from google.cloud.vision_v1p1beta1.types.image_annotator import AnnotateImageRequest +from google.cloud.vision_v1p1beta1.types.image_annotator import AnnotateImageResponse +from google.cloud.vision_v1p1beta1.types.image_annotator import BatchAnnotateImagesRequest +from google.cloud.vision_v1p1beta1.types.image_annotator import BatchAnnotateImagesResponse +from google.cloud.vision_v1p1beta1.types.image_annotator import ColorInfo +from google.cloud.vision_v1p1beta1.types.image_annotator import CropHint +from google.cloud.vision_v1p1beta1.types.image_annotator import CropHintsAnnotation +from google.cloud.vision_v1p1beta1.types.image_annotator import CropHintsParams +from google.cloud.vision_v1p1beta1.types.image_annotator import DominantColorsAnnotation +from google.cloud.vision_v1p1beta1.types.image_annotator import EntityAnnotation +from google.cloud.vision_v1p1beta1.types.image_annotator import FaceAnnotation +from google.cloud.vision_v1p1beta1.types.image_annotator import Feature +from google.cloud.vision_v1p1beta1.types.image_annotator import Image +from google.cloud.vision_v1p1beta1.types.image_annotator import ImageContext +from google.cloud.vision_v1p1beta1.types.image_annotator import ImageProperties +from google.cloud.vision_v1p1beta1.types.image_annotator import ImageSource +from google.cloud.vision_v1p1beta1.types.image_annotator import LatLongRect +from google.cloud.vision_v1p1beta1.types.image_annotator import LocationInfo +from google.cloud.vision_v1p1beta1.types.image_annotator import Property +from google.cloud.vision_v1p1beta1.types.image_annotator import SafeSearchAnnotation +from google.cloud.vision_v1p1beta1.types.image_annotator import TextDetectionParams +from google.cloud.vision_v1p1beta1.types.image_annotator import WebDetectionParams +from google.cloud.vision_v1p1beta1.types.image_annotator import Likelihood +from google.cloud.vision_v1p1beta1.types.text_annotation import Block +from google.cloud.vision_v1p1beta1.types.text_annotation import Page +from google.cloud.vision_v1p1beta1.types.text_annotation import Paragraph +from google.cloud.vision_v1p1beta1.types.text_annotation import Symbol +from google.cloud.vision_v1p1beta1.types.text_annotation import TextAnnotation +from google.cloud.vision_v1p1beta1.types.text_annotation import Word +from google.cloud.vision_v1p1beta1.types.web_detection import WebDetection + +__all__ = ('ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', + 'BoundingPoly', + 'Position', + 'Vertex', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'Image', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'LatLongRect', + 'LocationInfo', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py new file mode 100644 index 00000000..a0b8efb9 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py @@ -0,0 +1,90 @@ +# -*- 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.image_annotator import ImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient + +from .types.geometry import BoundingPoly +from .types.geometry import Position +from .types.geometry import Vertex +from .types.image_annotator import AnnotateImageRequest +from .types.image_annotator import AnnotateImageResponse +from .types.image_annotator import BatchAnnotateImagesRequest +from .types.image_annotator import BatchAnnotateImagesResponse +from .types.image_annotator import ColorInfo +from .types.image_annotator import CropHint +from .types.image_annotator import CropHintsAnnotation +from .types.image_annotator import CropHintsParams +from .types.image_annotator import DominantColorsAnnotation +from .types.image_annotator import EntityAnnotation +from .types.image_annotator import FaceAnnotation +from .types.image_annotator import Feature +from .types.image_annotator import Image +from .types.image_annotator import ImageContext +from .types.image_annotator import ImageProperties +from .types.image_annotator import ImageSource +from .types.image_annotator import LatLongRect +from .types.image_annotator import LocationInfo +from .types.image_annotator import Property +from .types.image_annotator import SafeSearchAnnotation +from .types.image_annotator import TextDetectionParams +from .types.image_annotator import WebDetectionParams +from .types.image_annotator import Likelihood +from .types.text_annotation import Block +from .types.text_annotation import Page +from .types.text_annotation import Paragraph +from .types.text_annotation import Symbol +from .types.text_annotation import TextAnnotation +from .types.text_annotation import Word +from .types.web_detection import WebDetection + +__all__ = ( + 'ImageAnnotatorAsyncClient', +'AnnotateImageRequest', +'AnnotateImageResponse', +'BatchAnnotateImagesRequest', +'BatchAnnotateImagesResponse', +'Block', +'BoundingPoly', +'ColorInfo', +'CropHint', +'CropHintsAnnotation', +'CropHintsParams', +'DominantColorsAnnotation', +'EntityAnnotation', +'FaceAnnotation', +'Feature', +'Image', +'ImageAnnotatorClient', +'ImageContext', +'ImageProperties', +'ImageSource', +'LatLongRect', +'Likelihood', +'LocationInfo', +'Page', +'Paragraph', +'Position', +'Property', +'SafeSearchAnnotation', +'Symbol', +'TextAnnotation', +'TextDetectionParams', +'Vertex', +'WebDetection', +'WebDetectionParams', +'Word', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json new file mode 100644 index 00000000..b198d92f --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json @@ -0,0 +1,33 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.vision_v1p1beta1", + "protoPackage": "google.cloud.vision.v1p1beta1", + "schema": "1.0", + "services": { + "ImageAnnotator": { + "clients": { + "grpc": { + "libraryClient": "ImageAnnotatorClient", + "rpcs": { + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ImageAnnotatorAsyncClient", + "rpcs": { + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/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/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py new file mode 100644 index 00000000..3cbfa2fa --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__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 ImageAnnotatorClient +from .async_client import ImageAnnotatorAsyncClient + +__all__ = ( + 'ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py new file mode 100644 index 00000000..f439455d --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py @@ -0,0 +1,241 @@ +# -*- 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.cloud.vision_v1p1beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport +from .client import ImageAnnotatorClient + + +class ImageAnnotatorAsyncClient: + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + _client: ImageAnnotatorClient + + DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT + + common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) + parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) + common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) + parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) + common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) + parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) + common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) + parse_common_location_path = staticmethod(ImageAnnotatorClient.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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def batch_annotate_images(self, + request: image_annotator.BatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (:class:`google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest`): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]`): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1p1beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorAsyncClient", +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py new file mode 100644 index 00000000..0f1ae394 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py @@ -0,0 +1,422 @@ +# -*- 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 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.cloud.vision_v1p1beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ImageAnnotatorGrpcTransport +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +class ImageAnnotatorClientMeta(type): + """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] + _transport_registry["grpc"] = ImageAnnotatorGrpcTransport + _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ImageAnnotatorTransport]: + """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + @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 = "vision.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: + ImageAnnotatorClient: 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: + ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: 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, ImageAnnotatorTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): + # transport is a ImageAnnotatorTransport 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, + always_use_jwt_access=True, + ) + + def batch_annotate_images(self, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (Union[google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest, dict]): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1p1beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 image_annotator.BatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): + request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorClient", +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py new file mode 100644 index 00000000..94f01250 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/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 ImageAnnotatorTransport +from .grpc import ImageAnnotatorGrpcTransport +from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] +_transport_registry['grpc'] = ImageAnnotatorGrpcTransport +_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport + +__all__ = ( + 'ImageAnnotatorTransport', + 'ImageAnnotatorGrpcTransport', + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py new file mode 100644 index 00000000..ebb9e3b0 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py @@ -0,0 +1,185 @@ +# -*- 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.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.vision_v1p1beta1.types import image_annotator + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-vision', + ).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 ImageAnnotatorTransport(abc.ABC): + """Abstract transport class for ImageAnnotator.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( + self.batch_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Union[ + image_annotator.BatchAnnotateImagesResponse, + Awaitable[image_annotator.BatchAnnotateImagesResponse] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ImageAnnotatorTransport', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py new file mode 100644 index 00000000..d8544cb2 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py @@ -0,0 +1,258 @@ +# -*- 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 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.vision_v1p1beta1.types import image_annotator +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO + + +class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): + """gRPC backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 application 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 the 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 a 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] = {} + + 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 = 'vision.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 batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + image_annotator.BatchAnnotateImagesResponse]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + ~.BatchAnnotateImagesResponse]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p1beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ImageAnnotatorGrpcTransport', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py new file mode 100644 index 00000000..50e4218f --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py @@ -0,0 +1,263 @@ +# -*- 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.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.vision_v1p1beta1.types import image_annotator +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .grpc import ImageAnnotatorGrpcTransport + + +class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): + """gRPC AsyncIO backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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] = {} + + 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 batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Awaitable[image_annotator.BatchAnnotateImagesResponse]]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + Awaitable[~.BatchAnnotateImagesResponse]]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p1beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py new file mode 100644 index 00000000..ec92dd01 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py @@ -0,0 +1,92 @@ +# -*- 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 .geometry import ( + BoundingPoly, + Position, + Vertex, +) +from .image_annotator import ( + AnnotateImageRequest, + AnnotateImageResponse, + BatchAnnotateImagesRequest, + BatchAnnotateImagesResponse, + ColorInfo, + CropHint, + CropHintsAnnotation, + CropHintsParams, + DominantColorsAnnotation, + EntityAnnotation, + FaceAnnotation, + Feature, + Image, + ImageContext, + ImageProperties, + ImageSource, + LatLongRect, + LocationInfo, + Property, + SafeSearchAnnotation, + TextDetectionParams, + WebDetectionParams, + Likelihood, +) +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) + +__all__ = ( + 'BoundingPoly', + 'Position', + 'Vertex', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'Image', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'LatLongRect', + 'LocationInfo', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py new file mode 100644 index 00000000..eafc97e6 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py @@ -0,0 +1,95 @@ +# -*- 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.vision.v1p1beta1', + manifest={ + 'Vertex', + 'BoundingPoly', + 'Position', + }, +) + + +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 BoundingPoly(proto.Message): + r"""A bounding polygon for the detected image annotation. + + Attributes: + vertices (Sequence[google.cloud.vision_v1p1beta1.types.Vertex]): + The bounding polygon vertices. + """ + + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Vertex', + ) + + +class Position(proto.Message): + r"""A 3D position in the image, used primarily for Face detection + landmarks. A valid Position must have both x and y coordinates. + The position coordinates are in the same scale as the original + image. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate. + z (float): + Z coordinate (or depth). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + z = proto.Field( + proto.FLOAT, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py new file mode 100644 index 00000000..42cecd96 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py @@ -0,0 +1,947 @@ +# -*- 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.vision_v1p1beta1.types import geometry +from google.cloud.vision_v1p1beta1.types import text_annotation +from google.cloud.vision_v1p1beta1.types import web_detection as gcv_web_detection +from google.rpc import status_pb2 # type: ignore +from google.type import color_pb2 # type: ignore +from google.type import latlng_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p1beta1', + manifest={ + 'Likelihood', + 'Feature', + 'ImageSource', + 'Image', + 'FaceAnnotation', + 'LocationInfo', + 'Property', + 'EntityAnnotation', + 'SafeSearchAnnotation', + 'LatLongRect', + 'ColorInfo', + 'DominantColorsAnnotation', + 'ImageProperties', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'WebDetectionParams', + 'TextDetectionParams', + 'ImageContext', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + }, +) + + +class Likelihood(proto.Enum): + r"""A bucketized representation of likelihood, which is intended + to give clients highly stable results across model upgrades. + """ + UNKNOWN = 0 + VERY_UNLIKELY = 1 + UNLIKELY = 2 + POSSIBLE = 3 + LIKELY = 4 + VERY_LIKELY = 5 + + +class Feature(proto.Message): + r"""Users describe the type of Google Cloud Vision API tasks to perform + over images by using *Feature*\ s. Each Feature indicates a type of + image detection task to perform. Features encode the Cloud Vision + API vertical to operate on and the number of top-scoring results to + return. + + Attributes: + type_ (google.cloud.vision_v1p1beta1.types.Feature.Type): + The feature type. + max_results (int): + Maximum number of results of this type. + model (str): + Model to use for the feature. + Supported values: "builtin/stable" (the default + if unset) and "builtin/latest". + """ + class Type(proto.Enum): + r"""Type of image feature.""" + TYPE_UNSPECIFIED = 0 + FACE_DETECTION = 1 + LANDMARK_DETECTION = 2 + LOGO_DETECTION = 3 + LABEL_DETECTION = 4 + TEXT_DETECTION = 5 + DOCUMENT_TEXT_DETECTION = 11 + SAFE_SEARCH_DETECTION = 6 + IMAGE_PROPERTIES = 7 + CROP_HINTS = 9 + WEB_DETECTION = 10 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum=Type, + ) + max_results = proto.Field( + proto.INT32, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + + +class ImageSource(proto.Message): + r"""External image source (Google Cloud Storage image location). + + Attributes: + gcs_image_uri (str): + NOTE: For new code ``image_uri`` below is preferred. Google + Cloud Storage image URI, which must be in the following + form: ``gs://bucket_name/object_name`` (for details, see + `Google Cloud Storage Request + URIs `__). + NOTE: Cloud Storage object versioning is not supported. + image_uri (str): + Image URI which supports: + + 1) Google Cloud Storage image URI, which must be in the + following form: ``gs://bucket_name/object_name`` (for + details, see `Google Cloud Storage Request + URIs `__). + NOTE: Cloud Storage object versioning is not supported. + 2) Publicly accessible image HTTP/HTTPS URL. This is + preferred over the legacy ``gcs_image_uri`` above. When + both ``gcs_image_uri`` and ``image_uri`` are specified, + ``image_uri`` takes precedence. + """ + + gcs_image_uri = proto.Field( + proto.STRING, + number=1, + ) + image_uri = proto.Field( + proto.STRING, + number=2, + ) + + +class Image(proto.Message): + r"""Client image to perform Google Cloud Vision API tasks over. + + Attributes: + content (bytes): + Image content, represented as a stream of bytes. Note: as + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + source (google.cloud.vision_v1p1beta1.types.ImageSource): + Google Cloud Storage image location. If both ``content`` and + ``source`` are provided for an image, ``content`` takes + precedence and is used to perform the image annotation + request. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + source = proto.Field( + proto.MESSAGE, + number=2, + message='ImageSource', + ) + + +class FaceAnnotation(proto.Message): + r"""A face annotation object contains the results of face + detection. + + Attributes: + bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The bounding polygon around the face. The coordinates of the + bounding box are in the original image's scale, as returned + in ``ImageParams``. The bounding box is computed to "frame" + the face in accordance with human expectations. It is based + on the landmarker results. Note that one or more x and/or y + coordinates may not be generated in the ``BoundingPoly`` + (the polygon will be unbounded) if only a partial face + appears in the image to be annotated. + fd_bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The ``fd_bounding_poly`` bounding polygon is tighter than + the ``boundingPoly``, and encloses only the skin part of the + face. Typically, it is used to eliminate the face from any + image analysis that detects the "amount of skin" visible in + an image. It is not based on the landmarker results, only on + the initial face detection, hence the fd (face detection) + prefix. + landmarks (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark]): + Detected face landmarks. + roll_angle (float): + Roll angle, which indicates the amount of + clockwise/anti-clockwise rotation of the face relative to + the image vertical about the axis perpendicular to the face. + Range [-180,180]. + pan_angle (float): + Yaw angle, which indicates the leftward/rightward angle that + the face is pointing relative to the vertical plane + perpendicular to the image. Range [-180,180]. + tilt_angle (float): + Pitch angle, which indicates the upwards/downwards angle + that the face is pointing relative to the image's horizontal + plane. Range [-180,180]. + detection_confidence (float): + Detection confidence. Range [0, 1]. + landmarking_confidence (float): + Face landmarking confidence. Range [0, 1]. + joy_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Joy likelihood. + sorrow_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Sorrow likelihood. + anger_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Anger likelihood. + surprise_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Surprise likelihood. + under_exposed_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Under-exposed likelihood. + blurred_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Blurred likelihood. + headwear_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): + Headwear likelihood. + """ + + class Landmark(proto.Message): + r"""A face-specific landmark (for example, a face feature). + + Attributes: + type_ (google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark.Type): + Face landmark type. + position (google.cloud.vision_v1p1beta1.types.Position): + Face landmark position. + """ + class Type(proto.Enum): + r"""Face landmark (feature) type. Left and right are defined from the + vantage of the viewer of the image without considering mirror + projections typical of photos. So, ``LEFT_EYE``, typically, is the + person's right eye. + """ + UNKNOWN_LANDMARK = 0 + LEFT_EYE = 1 + RIGHT_EYE = 2 + LEFT_OF_LEFT_EYEBROW = 3 + RIGHT_OF_LEFT_EYEBROW = 4 + LEFT_OF_RIGHT_EYEBROW = 5 + RIGHT_OF_RIGHT_EYEBROW = 6 + MIDPOINT_BETWEEN_EYES = 7 + NOSE_TIP = 8 + UPPER_LIP = 9 + LOWER_LIP = 10 + MOUTH_LEFT = 11 + MOUTH_RIGHT = 12 + MOUTH_CENTER = 13 + NOSE_BOTTOM_RIGHT = 14 + NOSE_BOTTOM_LEFT = 15 + NOSE_BOTTOM_CENTER = 16 + LEFT_EYE_TOP_BOUNDARY = 17 + LEFT_EYE_RIGHT_CORNER = 18 + LEFT_EYE_BOTTOM_BOUNDARY = 19 + LEFT_EYE_LEFT_CORNER = 20 + RIGHT_EYE_TOP_BOUNDARY = 21 + RIGHT_EYE_RIGHT_CORNER = 22 + RIGHT_EYE_BOTTOM_BOUNDARY = 23 + RIGHT_EYE_LEFT_CORNER = 24 + LEFT_EYEBROW_UPPER_MIDPOINT = 25 + RIGHT_EYEBROW_UPPER_MIDPOINT = 26 + LEFT_EAR_TRAGION = 27 + RIGHT_EAR_TRAGION = 28 + LEFT_EYE_PUPIL = 29 + RIGHT_EYE_PUPIL = 30 + FOREHEAD_GLABELLA = 31 + CHIN_GNATHION = 32 + CHIN_LEFT_GONION = 33 + CHIN_RIGHT_GONION = 34 + + type_ = proto.Field( + proto.ENUM, + number=3, + enum='FaceAnnotation.Landmark.Type', + ) + position = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.Position, + ) + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + fd_bounding_poly = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + landmarks = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Landmark, + ) + roll_angle = proto.Field( + proto.FLOAT, + number=4, + ) + pan_angle = proto.Field( + proto.FLOAT, + number=5, + ) + tilt_angle = proto.Field( + proto.FLOAT, + number=6, + ) + detection_confidence = proto.Field( + proto.FLOAT, + number=7, + ) + landmarking_confidence = proto.Field( + proto.FLOAT, + number=8, + ) + joy_likelihood = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + sorrow_likelihood = proto.Field( + proto.ENUM, + number=10, + enum='Likelihood', + ) + anger_likelihood = proto.Field( + proto.ENUM, + number=11, + enum='Likelihood', + ) + surprise_likelihood = proto.Field( + proto.ENUM, + number=12, + enum='Likelihood', + ) + under_exposed_likelihood = proto.Field( + proto.ENUM, + number=13, + enum='Likelihood', + ) + blurred_likelihood = proto.Field( + proto.ENUM, + number=14, + enum='Likelihood', + ) + headwear_likelihood = proto.Field( + proto.ENUM, + number=15, + enum='Likelihood', + ) + + +class LocationInfo(proto.Message): + r"""Detected entity location information. + + Attributes: + lat_lng (google.type.latlng_pb2.LatLng): + lat/long location coordinates. + """ + + lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + + +class Property(proto.Message): + r"""A ``Property`` consists of a user-supplied name/value pair. + + Attributes: + name (str): + Name of the property. + value (str): + Value of the property. + uint64_value (int): + Value of numeric properties. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + uint64_value = proto.Field( + proto.UINT64, + number=3, + ) + + +class EntityAnnotation(proto.Message): + r"""Set of detected entity features. + + Attributes: + mid (str): + Opaque entity ID. Some IDs may be available in `Google + Knowledge Graph Search + API `__. + locale (str): + The language code for the locale in which the entity textual + ``description`` is expressed. + description (str): + Entity textual description, expressed in its ``locale`` + language. + score (float): + Overall score of the result. Range [0, 1]. + confidence (float): + The accuracy of the entity detection in an image. For + example, for an image in which the "Eiffel Tower" entity is + detected, this field represents the confidence that there is + a tower in the query image. Range [0, 1]. + topicality (float): + The relevancy of the ICA (Image Content Annotation) label to + the image. For example, the relevancy of "tower" is likely + higher to an image containing the detected "Eiffel Tower" + than to an image containing a detected distant towering + building, even though the confidence that there is a tower + in each image may be the same. Range [0, 1]. + bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): + Image region to which this entity belongs. Not produced for + ``LABEL_DETECTION`` features. + locations (Sequence[google.cloud.vision_v1p1beta1.types.LocationInfo]): + The location information for the detected entity. Multiple + ``LocationInfo`` elements can be present because one + location may indicate the location of the scene in the + image, and another location may indicate the location of the + place where the image was taken. Location information is + usually present for landmarks. + properties (Sequence[google.cloud.vision_v1p1beta1.types.Property]): + Some entities may have optional user-supplied ``Property`` + (name/value) fields, such a score or string that qualifies + the entity. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + locale = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + topicality = proto.Field( + proto.FLOAT, + number=6, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=7, + message=geometry.BoundingPoly, + ) + locations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='LocationInfo', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Property', + ) + + +class SafeSearchAnnotation(proto.Message): + r"""Set of features pertaining to the image, computed by computer + vision methods over safe-search verticals (for example, adult, + spoof, medical, violence). + + Attributes: + adult (google.cloud.vision_v1p1beta1.types.Likelihood): + Represents the adult content likelihood for + the image. Adult content may contain elements + such as nudity, pornographic images or cartoons, + or sexual activities. + spoof (google.cloud.vision_v1p1beta1.types.Likelihood): + Spoof likelihood. The likelihood that an + modification was made to the image's canonical + version to make it appear funny or offensive. + medical (google.cloud.vision_v1p1beta1.types.Likelihood): + Likelihood that this is a medical image. + violence (google.cloud.vision_v1p1beta1.types.Likelihood): + Likelihood that this image contains violent + content. + racy (google.cloud.vision_v1p1beta1.types.Likelihood): + Likelihood that the request image contains + racy content. Racy content may include (but is + not limited to) skimpy or sheer clothing, + strategically covered nudity, lewd or + provocative poses, or close-ups of sensitive + body areas. + """ + + adult = proto.Field( + proto.ENUM, + number=1, + enum='Likelihood', + ) + spoof = proto.Field( + proto.ENUM, + number=2, + enum='Likelihood', + ) + medical = proto.Field( + proto.ENUM, + number=3, + enum='Likelihood', + ) + violence = proto.Field( + proto.ENUM, + number=4, + enum='Likelihood', + ) + racy = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + + +class LatLongRect(proto.Message): + r"""Rectangle determined by min and max ``LatLng`` pairs. + + Attributes: + min_lat_lng (google.type.latlng_pb2.LatLng): + Min lat/long pair. + max_lat_lng (google.type.latlng_pb2.LatLng): + Max lat/long pair. + """ + + min_lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + max_lat_lng = proto.Field( + proto.MESSAGE, + number=2, + message=latlng_pb2.LatLng, + ) + + +class ColorInfo(proto.Message): + r"""Color information consists of RGB channels, score, and the + fraction of the image that the color occupies in the image. + + Attributes: + color (google.type.color_pb2.Color): + RGB components of the color. + score (float): + Image-specific score for this color. Value in range [0, 1]. + pixel_fraction (float): + The fraction of pixels the color occupies in the image. + Value in range [0, 1]. + """ + + color = proto.Field( + proto.MESSAGE, + number=1, + message=color_pb2.Color, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + pixel_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class DominantColorsAnnotation(proto.Message): + r"""Set of dominant colors and their corresponding scores. + + Attributes: + colors (Sequence[google.cloud.vision_v1p1beta1.types.ColorInfo]): + RGB color values with their score and pixel + fraction. + """ + + colors = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ColorInfo', + ) + + +class ImageProperties(proto.Message): + r"""Stores image properties, such as dominant colors. + + Attributes: + dominant_colors (google.cloud.vision_v1p1beta1.types.DominantColorsAnnotation): + If present, dominant colors completed + successfully. + """ + + dominant_colors = proto.Field( + proto.MESSAGE, + number=1, + message='DominantColorsAnnotation', + ) + + +class CropHint(proto.Message): + r"""Single crop hint that is used to generate a new crop when + serving an image. + + Attributes: + bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The bounding polygon for the crop region. The coordinates of + the bounding box are in the original image's scale, as + returned in ``ImageParams``. + confidence (float): + Confidence of this being a salient region. Range [0, 1]. + importance_fraction (float): + Fraction of importance of this salient region + with respect to the original image. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + importance_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class CropHintsAnnotation(proto.Message): + r"""Set of crop hints that are used to generate new crops when + serving images. + + Attributes: + crop_hints (Sequence[google.cloud.vision_v1p1beta1.types.CropHint]): + Crop hint results. + """ + + crop_hints = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='CropHint', + ) + + +class CropHintsParams(proto.Message): + r"""Parameters for crop hints annotation request. + + Attributes: + aspect_ratios (Sequence[float]): + Aspect ratios in floats, representing the + ratio of the width to the height of the image. + For example, if the desired aspect ratio is 4/3, + the corresponding float value should be 1.33333. + If not specified, the best possible crop is + returned. The number of provided aspect ratios + is limited to a maximum of 16; any aspect ratios + provided after the 16th are ignored. + """ + + aspect_ratios = proto.RepeatedField( + proto.FLOAT, + number=1, + ) + + +class WebDetectionParams(proto.Message): + r"""Parameters for web detection request. + + Attributes: + include_geo_results (bool): + Whether to include results derived from the + geo information in the image. + """ + + include_geo_results = proto.Field( + proto.BOOL, + number=2, + ) + + +class TextDetectionParams(proto.Message): + r"""Parameters for text detections. This is used to control + TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. + + Attributes: + enable_text_detection_confidence_score (bool): + By default, Cloud Vision API only includes confidence score + for DOCUMENT_TEXT_DETECTION result. Set the flag to true to + include confidence score for TEXT_DETECTION as well. + """ + + enable_text_detection_confidence_score = proto.Field( + proto.BOOL, + number=9, + ) + + +class ImageContext(proto.Message): + r"""Image context and/or feature-specific parameters. + + Attributes: + lat_long_rect (google.cloud.vision_v1p1beta1.types.LatLongRect): + lat/long rectangle that specifies the + location of the image. + language_hints (Sequence[str]): + List of languages to use for TEXT_DETECTION. 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). + Text detection returns an error if one or more of the + specified languages is not one of the `supported + languages `__. + crop_hints_params (google.cloud.vision_v1p1beta1.types.CropHintsParams): + Parameters for crop hints annotation request. + web_detection_params (google.cloud.vision_v1p1beta1.types.WebDetectionParams): + Parameters for web detection. + text_detection_params (google.cloud.vision_v1p1beta1.types.TextDetectionParams): + Parameters for text detection and document + text detection. + """ + + lat_long_rect = proto.Field( + proto.MESSAGE, + number=1, + message='LatLongRect', + ) + language_hints = proto.RepeatedField( + proto.STRING, + number=2, + ) + crop_hints_params = proto.Field( + proto.MESSAGE, + number=4, + message='CropHintsParams', + ) + web_detection_params = proto.Field( + proto.MESSAGE, + number=6, + message='WebDetectionParams', + ) + text_detection_params = proto.Field( + proto.MESSAGE, + number=12, + message='TextDetectionParams', + ) + + +class AnnotateImageRequest(proto.Message): + r"""Request for performing Google Cloud Vision API tasks over a + user-provided image, with user-requested features. + + Attributes: + image (google.cloud.vision_v1p1beta1.types.Image): + The image to be processed. + features (Sequence[google.cloud.vision_v1p1beta1.types.Feature]): + Requested features. + image_context (google.cloud.vision_v1p1beta1.types.ImageContext): + Additional context that may accompany the + image. + """ + + image = proto.Field( + proto.MESSAGE, + number=1, + message='Image', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + + +class AnnotateImageResponse(proto.Message): + r"""Response to an image annotation request. + + Attributes: + face_annotations (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation]): + If present, face detection has completed + successfully. + landmark_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): + If present, landmark detection has completed + successfully. + logo_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): + If present, logo detection has completed + successfully. + label_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): + If present, label detection has completed + successfully. + text_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): + If present, text (OCR) detection has + completed successfully. + full_text_annotation (google.cloud.vision_v1p1beta1.types.TextAnnotation): + If present, text (OCR) detection or document + (OCR) text detection has completed successfully. + This annotation provides the structural + hierarchy for the OCR detected text. + safe_search_annotation (google.cloud.vision_v1p1beta1.types.SafeSearchAnnotation): + If present, safe-search annotation has + completed successfully. + image_properties_annotation (google.cloud.vision_v1p1beta1.types.ImageProperties): + If present, image properties were extracted + successfully. + crop_hints_annotation (google.cloud.vision_v1p1beta1.types.CropHintsAnnotation): + If present, crop hints have completed + successfully. + web_detection (google.cloud.vision_v1p1beta1.types.WebDetection): + If present, web detection has completed + successfully. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the operation. Note + that filled-in image annotations are guaranteed to be + correct, even when ``error`` is set. + """ + + face_annotations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='FaceAnnotation', + ) + landmark_annotations = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='EntityAnnotation', + ) + logo_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='EntityAnnotation', + ) + label_annotations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='EntityAnnotation', + ) + text_annotations = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='EntityAnnotation', + ) + full_text_annotation = proto.Field( + proto.MESSAGE, + number=12, + message=text_annotation.TextAnnotation, + ) + safe_search_annotation = proto.Field( + proto.MESSAGE, + number=6, + message='SafeSearchAnnotation', + ) + image_properties_annotation = proto.Field( + proto.MESSAGE, + number=8, + message='ImageProperties', + ) + crop_hints_annotation = proto.Field( + proto.MESSAGE, + number=11, + message='CropHintsAnnotation', + ) + web_detection = proto.Field( + proto.MESSAGE, + number=13, + message=gcv_web_detection.WebDetection, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + + +class BatchAnnotateImagesRequest(proto.Message): + r"""Multiple image annotation requests are batched into a single + service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + + +class BatchAnnotateImagesResponse(proto.Message): + r"""Response to a batch image annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageResponse]): + Individual responses to image annotation + requests within the batch. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageResponse', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py new file mode 100644 index 00000000..8b571866 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py @@ -0,0 +1,378 @@ +# -*- 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.vision_v1p1beta1.types import geometry + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p1beta1', + manifest={ + 'TextAnnotation', + 'Page', + 'Block', + 'Paragraph', + 'Word', + 'Symbol', + }, +) + + +class TextAnnotation(proto.Message): + r"""TextAnnotation contains a structured representation of OCR extracted + text. The hierarchy of an OCR extracted text structure is like this: + TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each + structural component, starting from Page, may further have their own + properties. Properties describe detected languages, breaks etc.. + Please refer to the + [TextAnnotation.TextProperty][google.cloud.vision.v1p1beta1.TextAnnotation.TextProperty] + message definition below for more detail. + + Attributes: + pages (Sequence[google.cloud.vision_v1p1beta1.types.Page]): + List of pages detected by OCR. + text (str): + UTF-8 text detected on the pages. + """ + + 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, + ) + + class DetectedBreak(proto.Message): + r"""Detected start or end of a structural component. + + Attributes: + type_ (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak.BreakType): + Detected break type. + is_prefix (bool): + True if break prepends the element. + """ + class BreakType(proto.Enum): + r"""Enum to denote the type of break found. New line, space etc.""" + UNKNOWN = 0 + SPACE = 1 + SURE_SPACE = 2 + EOL_SURE_SPACE = 3 + HYPHEN = 4 + LINE_BREAK = 5 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='TextAnnotation.DetectedBreak.BreakType', + ) + is_prefix = proto.Field( + proto.BOOL, + number=2, + ) + + class TextProperty(proto.Message): + r"""Additional information detected on the structural component. + + Attributes: + detected_languages (Sequence[google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedLanguage]): + A list of detected languages together with + confidence. + detected_break (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak): + Detected start or end of a text segment. + """ + + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='TextAnnotation.DetectedLanguage', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='TextAnnotation.DetectedBreak', + ) + + pages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Page', + ) + text = proto.Field( + proto.STRING, + number=2, + ) + + +class Page(proto.Message): + r"""Detected page from OCR. + + Attributes: + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): + Additional information detected on the page. + width (int): + Page width in pixels. + height (int): + Page height in pixels. + blocks (Sequence[google.cloud.vision_v1p1beta1.types.Block]): + List of blocks of text, images etc on this + page. + confidence (float): + Confidence of the OCR results on the page. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + width = proto.Field( + proto.INT32, + number=2, + ) + height = proto.Field( + proto.INT32, + number=3, + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Block', + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Block(proto.Message): + r"""Logical element on the page. + + Attributes: + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + block. + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The bounding box for the block. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + paragraphs (Sequence[google.cloud.vision_v1p1beta1.types.Paragraph]): + List of paragraphs in this block (if this + blocks is of type text). + block_type (google.cloud.vision_v1p1beta1.types.Block.BlockType): + Detected block type (text, image etc) for + this block. + confidence (float): + Confidence of the OCR results on the block. Range [0, 1]. + """ + class BlockType(proto.Enum): + r"""Type of a block (text, image etc) as identified by OCR.""" + UNKNOWN = 0 + TEXT = 1 + TABLE = 2 + PICTURE = 3 + RULER = 4 + BARCODE = 5 + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Paragraph', + ) + block_type = proto.Field( + proto.ENUM, + number=4, + enum=BlockType, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Paragraph(proto.Message): + r"""Structural unit of text representing a number of words in + certain order. + + Attributes: + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + paragraph. + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The bounding box for the paragraph. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + words (Sequence[google.cloud.vision_v1p1beta1.types.Word]): + List of words in this paragraph. + confidence (float): + Confidence of the OCR results for the paragraph. Range [0, + 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + words = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Word', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Word(proto.Message): + r"""A word representation. + + Attributes: + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): + Additional information detected for the word. + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The bounding box for the word. The vertices are in the order + of top-left, top-right, bottom-right, bottom-left. When a + rotation of the bounding box is detected the rotation is + represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + symbols (Sequence[google.cloud.vision_v1p1beta1.types.Symbol]): + List of symbols in the word. + The order of the symbols follows the natural + reading order. + confidence (float): + Confidence of the OCR results for the word. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + symbols = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Symbol', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Symbol(proto.Message): + r"""A single symbol representation. + + Attributes: + property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + symbol. + bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): + The bounding box for the symbol. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + text (str): + The actual UTF-8 representation of the + symbol. + confidence (float): + Confidence of the OCR results for the symbol. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + text = proto.Field( + proto.STRING, + number=3, + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py new file mode 100644 index 00000000..aeea2bf9 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py @@ -0,0 +1,199 @@ +# -*- 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.vision.v1p1beta1', + manifest={ + 'WebDetection', + }, +) + + +class WebDetection(proto.Message): + r"""Relevant information for the image from the Internet. + + Attributes: + web_entities (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebEntity]): + Deduced entities from similar images on the + Internet. + full_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): + Fully matching images from the Internet. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): + Partial matching images from the Internet. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + pages_with_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebPage]): + Web pages containing the matching images from + the Internet. + visually_similar_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): + The visually similar image results. + best_guess_labels (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebLabel]): + Best guess text labels for the request image. + """ + + class WebEntity(proto.Message): + r"""Entity deduced from similar images on the Internet. + + Attributes: + entity_id (str): + Opaque entity ID. + score (float): + Overall relevancy score for the entity. + Not normalized and not comparable across + different image queries. + description (str): + Canonical description of the entity, in + English. + """ + + entity_id = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + + class WebImage(proto.Message): + r"""Metadata for online images. + + Attributes: + url (str): + The result image URL. + score (float): + (Deprecated) Overall relevancy score for the + image. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + + class WebPage(proto.Message): + r"""Metadata for web pages. + + Attributes: + url (str): + The result web page URL. + score (float): + (Deprecated) Overall relevancy score for the + web page. + page_title (str): + Title for the web page, may contain HTML + markups. + full_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): + Fully matching images on the page. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): + Partial matching images on the page. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + page_title = proto.Field( + proto.STRING, + number=3, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='WebDetection.WebImage', + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='WebDetection.WebImage', + ) + + class WebLabel(proto.Message): + r"""Label to provide extra metadata for the web detection. + + Attributes: + label (str): + Label for extra metadata. + language_code (str): + The BCP-47 language code for ``label``, such as "en-US" or + "sr-Latn". For more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + """ + + label = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + + web_entities = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=WebEntity, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=WebImage, + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=WebImage, + ) + pages_with_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=WebPage, + ) + visually_similar_images = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=WebImage, + ) + best_guess_labels = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=WebLabel, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/mypy.ini b/owl-bot-staging/v1p1beta1/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1p1beta1/noxfile.py b/owl-bot-staging/v1p1beta1/noxfile.py new file mode 100644 index 00000000..e4d4b85e --- /dev/null +++ b/owl-bot-staging/v1p1beta1/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/vision_v1p1beta1/', + '--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/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py b/owl-bot-staging/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py new file mode 100644 index 00000000..9570c77b --- /dev/null +++ b/owl-bot-staging/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py @@ -0,0 +1,176 @@ +#! /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 visionCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'batch_annotate_images': ('requests', ), + } + + 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: a.keyword.value not 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=visionCallTransformer(), +): + """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 vision 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/v1p1beta1/setup.py b/owl-bot-staging/v1p1beta1/setup.py new file mode 100644 index 00000000..9d03e702 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/setup.py @@ -0,0 +1,54 @@ +# -*- 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-vision', + 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, < 3.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', + 'Programming Language :: Python :: 3.9', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1p1beta1/tests/__init__.py b/owl-bot-staging/v1p1beta1/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p1beta1/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/v1p1beta1/tests/unit/__init__.py b/owl-bot-staging/v1p1beta1/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p1beta1/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/v1p1beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p1beta1/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p1beta1/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/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__init__.py b/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__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/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py new file mode 100644 index 00000000..43b216a7 --- /dev/null +++ b/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py @@ -0,0 +1,1131 @@ +# -*- 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 gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1p1beta1.services.image_annotator import ImageAnnotatorAsyncClient +from google.cloud.vision_v1p1beta1.services.image_annotator import ImageAnnotatorClient +from google.cloud.vision_v1p1beta1.services.image_annotator import transports +from google.cloud.vision_v1p1beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1p1beta1.types import image_annotator +from google.oauth2 import service_account +from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ImageAnnotatorGrpcTransport, "grpc"), + (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +def test_image_annotator_client_get_transport_class(): + transport = ImageAnnotatorClient.get_transport_class() + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports + + transport = ImageAnnotatorClient.get_transport_class("grpc") + assert transport == transports.ImageAnnotatorGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + +def test_image_annotator_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ImageAnnotatorClient( + 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, + always_use_jwt_access=True, + ) + + +def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse( + ) + response = client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +def test_batch_annotate_images_from_dict(): + test_batch_annotate_images(request_type=dict) + + +def test_batch_annotate_images_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 = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + client.batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( + )) + response = await client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async_from_dict(): + await test_batch_annotate_images_async(request_type=dict) + + +def test_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +def test_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ImageAnnotatorClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, +]) +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 = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ImageAnnotatorGrpcTransport, + ) + +def test_image_annotator_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_image_annotator_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'batch_annotate_images', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ImageAnnotatorGrpcTransport, grpc_helpers), + (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_image_annotator_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_host_no_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_image_annotator_host_with_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_image_annotator_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcTransport( + 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_image_annotator_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ImageAnnotatorClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ImageAnnotatorClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = ImageAnnotatorClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ImageAnnotatorClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ImageAnnotatorClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ImageAnnotatorClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = ImageAnnotatorClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ImageAnnotatorClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ImageAnnotatorClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + transport_class = ImageAnnotatorClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1p2beta1/.coveragerc b/owl-bot-staging/v1p2beta1/.coveragerc new file mode 100644 index 00000000..75747063 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/vision/__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/v1p2beta1/MANIFEST.in b/owl-bot-staging/v1p2beta1/MANIFEST.in new file mode 100644 index 00000000..397ad4e2 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/vision *.py +recursive-include google/cloud/vision_v1p2beta1 *.py diff --git a/owl-bot-staging/v1p2beta1/README.rst b/owl-bot-staging/v1p2beta1/README.rst new file mode 100644 index 00000000..39f9ca72 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Vision 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 Vision 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/v1p2beta1/docs/conf.py b/owl-bot-staging/v1p2beta1/docs/conf.py new file mode 100644 index 00000000..6e730bf5 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/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-vision 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-vision" +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-vision-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-vision.tex", + u"google-cloud-vision 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-vision", + u"Google Cloud Vision 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-vision", + u"google-cloud-vision Documentation", + author, + "google-cloud-vision", + "GAPIC library for Google Cloud Vision 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/v1p2beta1/docs/index.rst b/owl-bot-staging/v1p2beta1/docs/index.rst new file mode 100644 index 00000000..d7cb733f --- /dev/null +++ b/owl-bot-staging/v1p2beta1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + vision_v1p2beta1/services + vision_v1p2beta1/types diff --git a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst new file mode 100644 index 00000000..d05fd549 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p2beta1.services.image_annotator + :members: + :inherited-members: diff --git a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst new file mode 100644 index 00000000..2272ceb5 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Vision v1p2beta1 API +============================================== +.. toctree:: + :maxdepth: 2 + + image_annotator diff --git a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst new file mode 100644 index 00000000..33ab32e0 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Vision v1p2beta1 API +=========================================== + +.. automodule:: google.cloud.vision_v1p2beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py new file mode 100644 index 00000000..71d258f3 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py @@ -0,0 +1,113 @@ +# -*- 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.vision_v1p2beta1.services.image_annotator.client import ImageAnnotatorClient +from google.cloud.vision_v1p2beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient + +from google.cloud.vision_v1p2beta1.types.geometry import BoundingPoly +from google.cloud.vision_v1p2beta1.types.geometry import NormalizedVertex +from google.cloud.vision_v1p2beta1.types.geometry import Position +from google.cloud.vision_v1p2beta1.types.geometry import Vertex +from google.cloud.vision_v1p2beta1.types.image_annotator import AnnotateFileResponse +from google.cloud.vision_v1p2beta1.types.image_annotator import AnnotateImageRequest +from google.cloud.vision_v1p2beta1.types.image_annotator import AnnotateImageResponse +from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncAnnotateFileRequest +from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncAnnotateFileResponse +from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncBatchAnnotateFilesRequest +from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncBatchAnnotateFilesResponse +from google.cloud.vision_v1p2beta1.types.image_annotator import BatchAnnotateImagesRequest +from google.cloud.vision_v1p2beta1.types.image_annotator import BatchAnnotateImagesResponse +from google.cloud.vision_v1p2beta1.types.image_annotator import ColorInfo +from google.cloud.vision_v1p2beta1.types.image_annotator import CropHint +from google.cloud.vision_v1p2beta1.types.image_annotator import CropHintsAnnotation +from google.cloud.vision_v1p2beta1.types.image_annotator import CropHintsParams +from google.cloud.vision_v1p2beta1.types.image_annotator import DominantColorsAnnotation +from google.cloud.vision_v1p2beta1.types.image_annotator import EntityAnnotation +from google.cloud.vision_v1p2beta1.types.image_annotator import FaceAnnotation +from google.cloud.vision_v1p2beta1.types.image_annotator import Feature +from google.cloud.vision_v1p2beta1.types.image_annotator import GcsDestination +from google.cloud.vision_v1p2beta1.types.image_annotator import GcsSource +from google.cloud.vision_v1p2beta1.types.image_annotator import Image +from google.cloud.vision_v1p2beta1.types.image_annotator import ImageAnnotationContext +from google.cloud.vision_v1p2beta1.types.image_annotator import ImageContext +from google.cloud.vision_v1p2beta1.types.image_annotator import ImageProperties +from google.cloud.vision_v1p2beta1.types.image_annotator import ImageSource +from google.cloud.vision_v1p2beta1.types.image_annotator import InputConfig +from google.cloud.vision_v1p2beta1.types.image_annotator import LatLongRect +from google.cloud.vision_v1p2beta1.types.image_annotator import LocationInfo +from google.cloud.vision_v1p2beta1.types.image_annotator import OperationMetadata +from google.cloud.vision_v1p2beta1.types.image_annotator import OutputConfig +from google.cloud.vision_v1p2beta1.types.image_annotator import Property +from google.cloud.vision_v1p2beta1.types.image_annotator import SafeSearchAnnotation +from google.cloud.vision_v1p2beta1.types.image_annotator import TextDetectionParams +from google.cloud.vision_v1p2beta1.types.image_annotator import WebDetectionParams +from google.cloud.vision_v1p2beta1.types.image_annotator import Likelihood +from google.cloud.vision_v1p2beta1.types.text_annotation import Block +from google.cloud.vision_v1p2beta1.types.text_annotation import Page +from google.cloud.vision_v1p2beta1.types.text_annotation import Paragraph +from google.cloud.vision_v1p2beta1.types.text_annotation import Symbol +from google.cloud.vision_v1p2beta1.types.text_annotation import TextAnnotation +from google.cloud.vision_v1p2beta1.types.text_annotation import Word +from google.cloud.vision_v1p2beta1.types.web_detection import WebDetection + +__all__ = ('ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', + 'BoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py new file mode 100644 index 00000000..76642da0 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py @@ -0,0 +1,114 @@ +# -*- 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.image_annotator import ImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient + +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Position +from .types.geometry import Vertex +from .types.image_annotator import AnnotateFileResponse +from .types.image_annotator import AnnotateImageRequest +from .types.image_annotator import AnnotateImageResponse +from .types.image_annotator import AsyncAnnotateFileRequest +from .types.image_annotator import AsyncAnnotateFileResponse +from .types.image_annotator import AsyncBatchAnnotateFilesRequest +from .types.image_annotator import AsyncBatchAnnotateFilesResponse +from .types.image_annotator import BatchAnnotateImagesRequest +from .types.image_annotator import BatchAnnotateImagesResponse +from .types.image_annotator import ColorInfo +from .types.image_annotator import CropHint +from .types.image_annotator import CropHintsAnnotation +from .types.image_annotator import CropHintsParams +from .types.image_annotator import DominantColorsAnnotation +from .types.image_annotator import EntityAnnotation +from .types.image_annotator import FaceAnnotation +from .types.image_annotator import Feature +from .types.image_annotator import GcsDestination +from .types.image_annotator import GcsSource +from .types.image_annotator import Image +from .types.image_annotator import ImageAnnotationContext +from .types.image_annotator import ImageContext +from .types.image_annotator import ImageProperties +from .types.image_annotator import ImageSource +from .types.image_annotator import InputConfig +from .types.image_annotator import LatLongRect +from .types.image_annotator import LocationInfo +from .types.image_annotator import OperationMetadata +from .types.image_annotator import OutputConfig +from .types.image_annotator import Property +from .types.image_annotator import SafeSearchAnnotation +from .types.image_annotator import TextDetectionParams +from .types.image_annotator import WebDetectionParams +from .types.image_annotator import Likelihood +from .types.text_annotation import Block +from .types.text_annotation import Page +from .types.text_annotation import Paragraph +from .types.text_annotation import Symbol +from .types.text_annotation import TextAnnotation +from .types.text_annotation import Word +from .types.web_detection import WebDetection + +__all__ = ( + 'ImageAnnotatorAsyncClient', +'AnnotateFileResponse', +'AnnotateImageRequest', +'AnnotateImageResponse', +'AsyncAnnotateFileRequest', +'AsyncAnnotateFileResponse', +'AsyncBatchAnnotateFilesRequest', +'AsyncBatchAnnotateFilesResponse', +'BatchAnnotateImagesRequest', +'BatchAnnotateImagesResponse', +'Block', +'BoundingPoly', +'ColorInfo', +'CropHint', +'CropHintsAnnotation', +'CropHintsParams', +'DominantColorsAnnotation', +'EntityAnnotation', +'FaceAnnotation', +'Feature', +'GcsDestination', +'GcsSource', +'Image', +'ImageAnnotationContext', +'ImageAnnotatorClient', +'ImageContext', +'ImageProperties', +'ImageSource', +'InputConfig', +'LatLongRect', +'Likelihood', +'LocationInfo', +'NormalizedVertex', +'OperationMetadata', +'OutputConfig', +'Page', +'Paragraph', +'Position', +'Property', +'SafeSearchAnnotation', +'Symbol', +'TextAnnotation', +'TextDetectionParams', +'Vertex', +'WebDetection', +'WebDetectionParams', +'Word', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/gapic_metadata.json b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/gapic_metadata.json new file mode 100644 index 00000000..3e166a99 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/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.vision_v1p2beta1", + "protoPackage": "google.cloud.vision.v1p2beta1", + "schema": "1.0", + "services": { + "ImageAnnotator": { + "clients": { + "grpc": { + "libraryClient": "ImageAnnotatorClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ImageAnnotatorAsyncClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/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/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py new file mode 100644 index 00000000..3cbfa2fa --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__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 ImageAnnotatorClient +from .async_client import ImageAnnotatorAsyncClient + +__all__ = ( + 'ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py new file mode 100644 index 00000000..0ab7254b --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py @@ -0,0 +1,334 @@ +# -*- 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.vision_v1p2beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport +from .client import ImageAnnotatorClient + + +class ImageAnnotatorAsyncClient: + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + _client: ImageAnnotatorClient + + DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT + + common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) + parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) + common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) + parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) + common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) + parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) + common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) + parse_common_location_path = staticmethod(ImageAnnotatorClient.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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def batch_annotate_images(self, + request: image_annotator.BatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (:class:`google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest`): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]`): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1p2beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def async_batch_annotate_files(self, + request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Run async image detection and annotation for a list of generic + files (e.g. PDF) which may contain multiple pages and multiple + images per page. Progress and results can be retrieved through + the ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (:class:`google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest`): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]`): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1p2beta1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorAsyncClient", +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py new file mode 100644 index 00000000..9a55ea78 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py @@ -0,0 +1,508 @@ +# -*- 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 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.vision_v1p2beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ImageAnnotatorGrpcTransport +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +class ImageAnnotatorClientMeta(type): + """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] + _transport_registry["grpc"] = ImageAnnotatorGrpcTransport + _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ImageAnnotatorTransport]: + """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + @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 = "vision.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: + ImageAnnotatorClient: 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: + ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: 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, ImageAnnotatorTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): + # transport is a ImageAnnotatorTransport 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, + always_use_jwt_access=True, + ) + + def batch_annotate_images(self, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (Union[google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest, dict]): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1p2beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 image_annotator.BatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): + request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def async_batch_annotate_files(self, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Run async image detection and annotation for a list of generic + files (e.g. PDF) which may contain multiple pages and multiple + images per page. Progress and results can be retrieved through + the ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (Union[google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest, dict]): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1p2beta1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 image_annotator.AsyncBatchAnnotateFilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): + request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorClient", +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py new file mode 100644 index 00000000..94f01250 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/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 ImageAnnotatorTransport +from .grpc import ImageAnnotatorGrpcTransport +from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] +_transport_registry['grpc'] = ImageAnnotatorGrpcTransport +_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport + +__all__ = ( + 'ImageAnnotatorTransport', + 'ImageAnnotatorGrpcTransport', + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py new file mode 100644 index 00000000..6a6810f7 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py @@ -0,0 +1,213 @@ +# -*- 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.vision_v1p2beta1.types import image_annotator +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-vision', + ).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 ImageAnnotatorTransport(abc.ABC): + """Abstract transport class for ImageAnnotator.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( + self.batch_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.async_batch_annotate_files: gapic_v1.method.wrap_method( + self.async_batch_annotate_files, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Union[ + image_annotator.BatchAnnotateImagesResponse, + Awaitable[image_annotator.BatchAnnotateImagesResponse] + ]]: + raise NotImplementedError() + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ImageAnnotatorTransport', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py new file mode 100644 index 00000000..48661c3f --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.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 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.vision_v1p2beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO + + +class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): + """gRPC backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + image_annotator.BatchAnnotateImagesResponse]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + ~.BatchAnnotateImagesResponse]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p2beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + operations_pb2.Operation]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run async image detection and annotation for a list of generic + files (e.g. PDF) which may contain multiple pages and multiple + images per page. Progress and results can be retrieved through + the ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + ~.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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ImageAnnotatorGrpcTransport', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py new file mode 100644 index 00000000..4276ae50 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py @@ -0,0 +1,314 @@ +# -*- 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.vision_v1p2beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .grpc import ImageAnnotatorGrpcTransport + + +class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): + """gRPC AsyncIO backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Awaitable[image_annotator.BatchAnnotateImagesResponse]]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + Awaitable[~.BatchAnnotateImagesResponse]]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p2beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run async image detection and annotation for a list of generic + files (e.g. PDF) which may contain multiple pages and multiple + images per page. Progress and results can be retrieved through + the ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + 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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py new file mode 100644 index 00000000..749f2495 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py @@ -0,0 +1,116 @@ +# -*- 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 .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) +from .image_annotator import ( + AnnotateFileResponse, + AnnotateImageRequest, + AnnotateImageResponse, + AsyncAnnotateFileRequest, + AsyncAnnotateFileResponse, + AsyncBatchAnnotateFilesRequest, + AsyncBatchAnnotateFilesResponse, + BatchAnnotateImagesRequest, + BatchAnnotateImagesResponse, + ColorInfo, + CropHint, + CropHintsAnnotation, + CropHintsParams, + DominantColorsAnnotation, + EntityAnnotation, + FaceAnnotation, + Feature, + GcsDestination, + GcsSource, + Image, + ImageAnnotationContext, + ImageContext, + ImageProperties, + ImageSource, + InputConfig, + LatLongRect, + LocationInfo, + OperationMetadata, + OutputConfig, + Property, + SafeSearchAnnotation, + TextDetectionParams, + WebDetectionParams, + Likelihood, +) +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) + +__all__ = ( + 'BoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py new file mode 100644 index 00000000..03b876c4 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py @@ -0,0 +1,125 @@ +# -*- 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.vision.v1p2beta1', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + 'Position', + }, +) + + +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.vision_v1p2beta1.types.Vertex]): + The bounding polygon vertices. + normalized_vertices (Sequence[google.cloud.vision_v1p2beta1.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', + ) + + +class Position(proto.Message): + r"""A 3D position in the image, used primarily for Face detection + landmarks. A valid Position must have both x and y coordinates. + The position coordinates are in the same scale as the original + image. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate. + z (float): + Z coordinate (or depth). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + z = proto.Field( + proto.FLOAT, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py new file mode 100644 index 00000000..6af9e3ed --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py @@ -0,0 +1,1256 @@ +# -*- 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.vision_v1p2beta1.types import geometry +from google.cloud.vision_v1p2beta1.types import text_annotation +from google.cloud.vision_v1p2beta1.types import web_detection as gcv_web_detection +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 latlng_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p2beta1', + manifest={ + 'Likelihood', + 'Feature', + 'ImageSource', + 'Image', + 'FaceAnnotation', + 'LocationInfo', + 'Property', + 'EntityAnnotation', + 'SafeSearchAnnotation', + 'LatLongRect', + 'ColorInfo', + 'DominantColorsAnnotation', + 'ImageProperties', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'WebDetectionParams', + 'TextDetectionParams', + 'ImageContext', + 'AnnotateImageRequest', + 'ImageAnnotationContext', + 'AnnotateImageResponse', + 'AnnotateFileResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'InputConfig', + 'OutputConfig', + 'GcsSource', + 'GcsDestination', + 'OperationMetadata', + }, +) + + +class Likelihood(proto.Enum): + r"""A bucketized representation of likelihood, which is intended + to give clients highly stable results across model upgrades. + """ + UNKNOWN = 0 + VERY_UNLIKELY = 1 + UNLIKELY = 2 + POSSIBLE = 3 + LIKELY = 4 + VERY_LIKELY = 5 + + +class Feature(proto.Message): + r"""The type of Google Cloud Vision API detection to perform, and the + maximum number of results to return for that type. Multiple + ``Feature`` objects can be specified in the ``features`` list. + + Attributes: + type_ (google.cloud.vision_v1p2beta1.types.Feature.Type): + The feature type. + max_results (int): + Maximum number of results of this type. Does not apply to + ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or + ``CROP_HINTS``. + model (str): + Model to use for the feature. + Supported values: "builtin/stable" (the default + if unset) and "builtin/latest". + """ + class Type(proto.Enum): + r"""Type of Google Cloud Vision API feature to be extracted.""" + TYPE_UNSPECIFIED = 0 + FACE_DETECTION = 1 + LANDMARK_DETECTION = 2 + LOGO_DETECTION = 3 + LABEL_DETECTION = 4 + TEXT_DETECTION = 5 + DOCUMENT_TEXT_DETECTION = 11 + SAFE_SEARCH_DETECTION = 6 + IMAGE_PROPERTIES = 7 + CROP_HINTS = 9 + WEB_DETECTION = 10 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum=Type, + ) + max_results = proto.Field( + proto.INT32, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + + +class ImageSource(proto.Message): + r"""External image source (Google Cloud Storage or web URL image + location). + + Attributes: + gcs_image_uri (str): + **Use ``image_uri`` instead.** + + The 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. + image_uri (str): + The URI of the source image. Can be either: + + 1. A 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. + + 2. A publicly-accessible image HTTP/HTTPS URL. When fetching + images from HTTP/HTTPS URLs, Google cannot guarantee that + the request will be completed. Your request may fail if + the specified host denies the request (e.g. due to + request throttling or DOS prevention), or if Google + throttles requests to the site for abuse prevention. You + should not depend on externally-hosted images for + production applications. + + When both ``gcs_image_uri`` and ``image_uri`` are specified, + ``image_uri`` takes precedence. + """ + + gcs_image_uri = proto.Field( + proto.STRING, + number=1, + ) + image_uri = proto.Field( + proto.STRING, + number=2, + ) + + +class Image(proto.Message): + r"""Client image to perform Google Cloud Vision API tasks over. + + Attributes: + content (bytes): + Image content, represented as a stream of bytes. Note: As + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + source (google.cloud.vision_v1p2beta1.types.ImageSource): + Google Cloud Storage image location, or publicly-accessible + image URL. If both ``content`` and ``source`` are provided + for an image, ``content`` takes precedence and is used to + perform the image annotation request. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + source = proto.Field( + proto.MESSAGE, + number=2, + message='ImageSource', + ) + + +class FaceAnnotation(proto.Message): + r"""A face annotation object contains the results of face + detection. + + Attributes: + bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The bounding polygon around the face. The coordinates of the + bounding box are in the original image's scale, as returned + in ``ImageParams``. The bounding box is computed to "frame" + the face in accordance with human expectations. It is based + on the landmarker results. Note that one or more x and/or y + coordinates may not be generated in the ``BoundingPoly`` + (the polygon will be unbounded) if only a partial face + appears in the image to be annotated. + fd_bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The ``fd_bounding_poly`` bounding polygon is tighter than + the ``boundingPoly``, and encloses only the skin part of the + face. Typically, it is used to eliminate the face from any + image analysis that detects the "amount of skin" visible in + an image. It is not based on the landmarker results, only on + the initial face detection, hence the fd (face detection) + prefix. + landmarks (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark]): + Detected face landmarks. + roll_angle (float): + Roll angle, which indicates the amount of + clockwise/anti-clockwise rotation of the face relative to + the image vertical about the axis perpendicular to the face. + Range [-180,180]. + pan_angle (float): + Yaw angle, which indicates the leftward/rightward angle that + the face is pointing relative to the vertical plane + perpendicular to the image. Range [-180,180]. + tilt_angle (float): + Pitch angle, which indicates the upwards/downwards angle + that the face is pointing relative to the image's horizontal + plane. Range [-180,180]. + detection_confidence (float): + Detection confidence. Range [0, 1]. + landmarking_confidence (float): + Face landmarking confidence. Range [0, 1]. + joy_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Joy likelihood. + sorrow_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Sorrow likelihood. + anger_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Anger likelihood. + surprise_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Surprise likelihood. + under_exposed_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Under-exposed likelihood. + blurred_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Blurred likelihood. + headwear_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): + Headwear likelihood. + """ + + class Landmark(proto.Message): + r"""A face-specific landmark (for example, a face feature). + + Attributes: + type_ (google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark.Type): + Face landmark type. + position (google.cloud.vision_v1p2beta1.types.Position): + Face landmark position. + """ + class Type(proto.Enum): + r"""Face landmark (feature) type. Left and right are defined from the + vantage of the viewer of the image without considering mirror + projections typical of photos. So, ``LEFT_EYE``, typically, is the + person's right eye. + """ + UNKNOWN_LANDMARK = 0 + LEFT_EYE = 1 + RIGHT_EYE = 2 + LEFT_OF_LEFT_EYEBROW = 3 + RIGHT_OF_LEFT_EYEBROW = 4 + LEFT_OF_RIGHT_EYEBROW = 5 + RIGHT_OF_RIGHT_EYEBROW = 6 + MIDPOINT_BETWEEN_EYES = 7 + NOSE_TIP = 8 + UPPER_LIP = 9 + LOWER_LIP = 10 + MOUTH_LEFT = 11 + MOUTH_RIGHT = 12 + MOUTH_CENTER = 13 + NOSE_BOTTOM_RIGHT = 14 + NOSE_BOTTOM_LEFT = 15 + NOSE_BOTTOM_CENTER = 16 + LEFT_EYE_TOP_BOUNDARY = 17 + LEFT_EYE_RIGHT_CORNER = 18 + LEFT_EYE_BOTTOM_BOUNDARY = 19 + LEFT_EYE_LEFT_CORNER = 20 + RIGHT_EYE_TOP_BOUNDARY = 21 + RIGHT_EYE_RIGHT_CORNER = 22 + RIGHT_EYE_BOTTOM_BOUNDARY = 23 + RIGHT_EYE_LEFT_CORNER = 24 + LEFT_EYEBROW_UPPER_MIDPOINT = 25 + RIGHT_EYEBROW_UPPER_MIDPOINT = 26 + LEFT_EAR_TRAGION = 27 + RIGHT_EAR_TRAGION = 28 + LEFT_EYE_PUPIL = 29 + RIGHT_EYE_PUPIL = 30 + FOREHEAD_GLABELLA = 31 + CHIN_GNATHION = 32 + CHIN_LEFT_GONION = 33 + CHIN_RIGHT_GONION = 34 + + type_ = proto.Field( + proto.ENUM, + number=3, + enum='FaceAnnotation.Landmark.Type', + ) + position = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.Position, + ) + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + fd_bounding_poly = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + landmarks = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Landmark, + ) + roll_angle = proto.Field( + proto.FLOAT, + number=4, + ) + pan_angle = proto.Field( + proto.FLOAT, + number=5, + ) + tilt_angle = proto.Field( + proto.FLOAT, + number=6, + ) + detection_confidence = proto.Field( + proto.FLOAT, + number=7, + ) + landmarking_confidence = proto.Field( + proto.FLOAT, + number=8, + ) + joy_likelihood = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + sorrow_likelihood = proto.Field( + proto.ENUM, + number=10, + enum='Likelihood', + ) + anger_likelihood = proto.Field( + proto.ENUM, + number=11, + enum='Likelihood', + ) + surprise_likelihood = proto.Field( + proto.ENUM, + number=12, + enum='Likelihood', + ) + under_exposed_likelihood = proto.Field( + proto.ENUM, + number=13, + enum='Likelihood', + ) + blurred_likelihood = proto.Field( + proto.ENUM, + number=14, + enum='Likelihood', + ) + headwear_likelihood = proto.Field( + proto.ENUM, + number=15, + enum='Likelihood', + ) + + +class LocationInfo(proto.Message): + r"""Detected entity location information. + + Attributes: + lat_lng (google.type.latlng_pb2.LatLng): + lat/long location coordinates. + """ + + lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + + +class Property(proto.Message): + r"""A ``Property`` consists of a user-supplied name/value pair. + + Attributes: + name (str): + Name of the property. + value (str): + Value of the property. + uint64_value (int): + Value of numeric properties. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + uint64_value = proto.Field( + proto.UINT64, + number=3, + ) + + +class EntityAnnotation(proto.Message): + r"""Set of detected entity features. + + Attributes: + mid (str): + Opaque entity ID. Some IDs may be available in `Google + Knowledge Graph Search + API `__. + locale (str): + The language code for the locale in which the entity textual + ``description`` is expressed. + description (str): + Entity textual description, expressed in its ``locale`` + language. + score (float): + Overall score of the result. Range [0, 1]. + confidence (float): + **Deprecated. Use ``score`` instead.** The accuracy of the + entity detection in an image. For example, for an image in + which the "Eiffel Tower" entity is detected, this field + represents the confidence that there is a tower in the query + image. Range [0, 1]. + topicality (float): + The relevancy of the ICA (Image Content Annotation) label to + the image. For example, the relevancy of "tower" is likely + higher to an image containing the detected "Eiffel Tower" + than to an image containing a detected distant towering + building, even though the confidence that there is a tower + in each image may be the same. Range [0, 1]. + bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): + Image region to which this entity belongs. Not produced for + ``LABEL_DETECTION`` features. + locations (Sequence[google.cloud.vision_v1p2beta1.types.LocationInfo]): + The location information for the detected entity. Multiple + ``LocationInfo`` elements can be present because one + location may indicate the location of the scene in the + image, and another location may indicate the location of the + place where the image was taken. Location information is + usually present for landmarks. + properties (Sequence[google.cloud.vision_v1p2beta1.types.Property]): + Some entities may have optional user-supplied ``Property`` + (name/value) fields, such a score or string that qualifies + the entity. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + locale = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + topicality = proto.Field( + proto.FLOAT, + number=6, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=7, + message=geometry.BoundingPoly, + ) + locations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='LocationInfo', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Property', + ) + + +class SafeSearchAnnotation(proto.Message): + r"""Set of features pertaining to the image, computed by computer + vision methods over safe-search verticals (for example, adult, + spoof, medical, violence). + + Attributes: + adult (google.cloud.vision_v1p2beta1.types.Likelihood): + Represents the adult content likelihood for + the image. Adult content may contain elements + such as nudity, pornographic images or cartoons, + or sexual activities. + spoof (google.cloud.vision_v1p2beta1.types.Likelihood): + Spoof likelihood. The likelihood that an + modification was made to the image's canonical + version to make it appear funny or offensive. + medical (google.cloud.vision_v1p2beta1.types.Likelihood): + Likelihood that this is a medical image. + violence (google.cloud.vision_v1p2beta1.types.Likelihood): + Likelihood that this image contains violent + content. + racy (google.cloud.vision_v1p2beta1.types.Likelihood): + Likelihood that the request image contains + racy content. Racy content may include (but is + not limited to) skimpy or sheer clothing, + strategically covered nudity, lewd or + provocative poses, or close-ups of sensitive + body areas. + """ + + adult = proto.Field( + proto.ENUM, + number=1, + enum='Likelihood', + ) + spoof = proto.Field( + proto.ENUM, + number=2, + enum='Likelihood', + ) + medical = proto.Field( + proto.ENUM, + number=3, + enum='Likelihood', + ) + violence = proto.Field( + proto.ENUM, + number=4, + enum='Likelihood', + ) + racy = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + + +class LatLongRect(proto.Message): + r"""Rectangle determined by min and max ``LatLng`` pairs. + + Attributes: + min_lat_lng (google.type.latlng_pb2.LatLng): + Min lat/long pair. + max_lat_lng (google.type.latlng_pb2.LatLng): + Max lat/long pair. + """ + + min_lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + max_lat_lng = proto.Field( + proto.MESSAGE, + number=2, + message=latlng_pb2.LatLng, + ) + + +class ColorInfo(proto.Message): + r"""Color information consists of RGB channels, score, and the + fraction of the image that the color occupies in the image. + + Attributes: + color (google.type.color_pb2.Color): + RGB components of the color. + score (float): + Image-specific score for this color. Value in range [0, 1]. + pixel_fraction (float): + The fraction of pixels the color occupies in the image. + Value in range [0, 1]. + """ + + color = proto.Field( + proto.MESSAGE, + number=1, + message=color_pb2.Color, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + pixel_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class DominantColorsAnnotation(proto.Message): + r"""Set of dominant colors and their corresponding scores. + + Attributes: + colors (Sequence[google.cloud.vision_v1p2beta1.types.ColorInfo]): + RGB color values with their score and pixel + fraction. + """ + + colors = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ColorInfo', + ) + + +class ImageProperties(proto.Message): + r"""Stores image properties, such as dominant colors. + + Attributes: + dominant_colors (google.cloud.vision_v1p2beta1.types.DominantColorsAnnotation): + If present, dominant colors completed + successfully. + """ + + dominant_colors = proto.Field( + proto.MESSAGE, + number=1, + message='DominantColorsAnnotation', + ) + + +class CropHint(proto.Message): + r"""Single crop hint that is used to generate a new crop when + serving an image. + + Attributes: + bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The bounding polygon for the crop region. The coordinates of + the bounding box are in the original image's scale, as + returned in ``ImageParams``. + confidence (float): + Confidence of this being a salient region. Range [0, 1]. + importance_fraction (float): + Fraction of importance of this salient region + with respect to the original image. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + importance_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class CropHintsAnnotation(proto.Message): + r"""Set of crop hints that are used to generate new crops when + serving images. + + Attributes: + crop_hints (Sequence[google.cloud.vision_v1p2beta1.types.CropHint]): + Crop hint results. + """ + + crop_hints = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='CropHint', + ) + + +class CropHintsParams(proto.Message): + r"""Parameters for crop hints annotation request. + + Attributes: + aspect_ratios (Sequence[float]): + Aspect ratios in floats, representing the + ratio of the width to the height of the image. + For example, if the desired aspect ratio is 4/3, + the corresponding float value should be 1.33333. + If not specified, the best possible crop is + returned. The number of provided aspect ratios + is limited to a maximum of 16; any aspect ratios + provided after the 16th are ignored. + """ + + aspect_ratios = proto.RepeatedField( + proto.FLOAT, + number=1, + ) + + +class WebDetectionParams(proto.Message): + r"""Parameters for web detection request. + + Attributes: + include_geo_results (bool): + Whether to include results derived from the + geo information in the image. + """ + + include_geo_results = proto.Field( + proto.BOOL, + number=2, + ) + + +class TextDetectionParams(proto.Message): + r"""Parameters for text detections. This is used to control + TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. + + Attributes: + enable_text_detection_confidence_score (bool): + By default, Cloud Vision API only includes confidence score + for DOCUMENT_TEXT_DETECTION result. Set the flag to true to + include confidence score for TEXT_DETECTION as well. + """ + + enable_text_detection_confidence_score = proto.Field( + proto.BOOL, + number=9, + ) + + +class ImageContext(proto.Message): + r"""Image context and/or feature-specific parameters. + + Attributes: + lat_long_rect (google.cloud.vision_v1p2beta1.types.LatLongRect): + Not used. + language_hints (Sequence[str]): + List of languages to use for TEXT_DETECTION. 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). + Text detection returns an error if one or more of the + specified languages is not one of the `supported + languages `__. + crop_hints_params (google.cloud.vision_v1p2beta1.types.CropHintsParams): + Parameters for crop hints annotation request. + web_detection_params (google.cloud.vision_v1p2beta1.types.WebDetectionParams): + Parameters for web detection. + text_detection_params (google.cloud.vision_v1p2beta1.types.TextDetectionParams): + Parameters for text detection and document + text detection. + """ + + lat_long_rect = proto.Field( + proto.MESSAGE, + number=1, + message='LatLongRect', + ) + language_hints = proto.RepeatedField( + proto.STRING, + number=2, + ) + crop_hints_params = proto.Field( + proto.MESSAGE, + number=4, + message='CropHintsParams', + ) + web_detection_params = proto.Field( + proto.MESSAGE, + number=6, + message='WebDetectionParams', + ) + text_detection_params = proto.Field( + proto.MESSAGE, + number=12, + message='TextDetectionParams', + ) + + +class AnnotateImageRequest(proto.Message): + r"""Request for performing Google Cloud Vision API tasks over a + user-provided image, with user-requested features. + + Attributes: + image (google.cloud.vision_v1p2beta1.types.Image): + The image to be processed. + features (Sequence[google.cloud.vision_v1p2beta1.types.Feature]): + Requested features. + image_context (google.cloud.vision_v1p2beta1.types.ImageContext): + Additional context that may accompany the + image. + """ + + image = proto.Field( + proto.MESSAGE, + number=1, + message='Image', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + + +class ImageAnnotationContext(proto.Message): + r"""If an image was produced from a file (e.g. a PDF), this + message gives information about the source of that image. + + Attributes: + uri (str): + The URI of the file used to produce the + image. + page_number (int): + If the file was a PDF or TIFF, this field + gives the page number within the file used to + produce the image. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + page_number = proto.Field( + proto.INT32, + number=2, + ) + + +class AnnotateImageResponse(proto.Message): + r"""Response to an image annotation request. + + Attributes: + face_annotations (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation]): + If present, face detection has completed + successfully. + landmark_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): + If present, landmark detection has completed + successfully. + logo_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): + If present, logo detection has completed + successfully. + label_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): + If present, label detection has completed + successfully. + text_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): + If present, text (OCR) detection has + completed successfully. + full_text_annotation (google.cloud.vision_v1p2beta1.types.TextAnnotation): + If present, text (OCR) detection or document + (OCR) text detection has completed successfully. + This annotation provides the structural + hierarchy for the OCR detected text. + safe_search_annotation (google.cloud.vision_v1p2beta1.types.SafeSearchAnnotation): + If present, safe-search annotation has + completed successfully. + image_properties_annotation (google.cloud.vision_v1p2beta1.types.ImageProperties): + If present, image properties were extracted + successfully. + crop_hints_annotation (google.cloud.vision_v1p2beta1.types.CropHintsAnnotation): + If present, crop hints have completed + successfully. + web_detection (google.cloud.vision_v1p2beta1.types.WebDetection): + If present, web detection has completed + successfully. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the operation. Note + that filled-in image annotations are guaranteed to be + correct, even when ``error`` is set. + context (google.cloud.vision_v1p2beta1.types.ImageAnnotationContext): + If present, contextual information is needed + to understand where this image comes from. + """ + + face_annotations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='FaceAnnotation', + ) + landmark_annotations = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='EntityAnnotation', + ) + logo_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='EntityAnnotation', + ) + label_annotations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='EntityAnnotation', + ) + text_annotations = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='EntityAnnotation', + ) + full_text_annotation = proto.Field( + proto.MESSAGE, + number=12, + message=text_annotation.TextAnnotation, + ) + safe_search_annotation = proto.Field( + proto.MESSAGE, + number=6, + message='SafeSearchAnnotation', + ) + image_properties_annotation = proto.Field( + proto.MESSAGE, + number=8, + message='ImageProperties', + ) + crop_hints_annotation = proto.Field( + proto.MESSAGE, + number=11, + message='CropHintsAnnotation', + ) + web_detection = proto.Field( + proto.MESSAGE, + number=13, + message=gcv_web_detection.WebDetection, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + context = proto.Field( + proto.MESSAGE, + number=21, + message='ImageAnnotationContext', + ) + + +class AnnotateFileResponse(proto.Message): + r"""Response to a single file annotation request. A file may + contain one or more images, which individually have their own + responses. + + Attributes: + input_config (google.cloud.vision_v1p2beta1.types.InputConfig): + Information about the file for which this + response is generated. + responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): + Individual responses to images found within + the file. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + responses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='AnnotateImageResponse', + ) + + +class BatchAnnotateImagesRequest(proto.Message): + r"""Multiple image annotation requests are batched into a single + service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + + +class BatchAnnotateImagesResponse(proto.Message): + r"""Response to a batch image annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): + Individual responses to image annotation + requests within the batch. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageResponse', + ) + + +class AsyncAnnotateFileRequest(proto.Message): + r"""An offline file annotation request. + + Attributes: + input_config (google.cloud.vision_v1p2beta1.types.InputConfig): + Required. Information about the input file. + features (Sequence[google.cloud.vision_v1p2beta1.types.Feature]): + Required. Requested features. + image_context (google.cloud.vision_v1p2beta1.types.ImageContext): + Additional context that may accompany the + image(s) in the file. + output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): + Required. The desired output location and + metadata (e.g. format). + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + output_config = proto.Field( + proto.MESSAGE, + number=4, + message='OutputConfig', + ) + + +class AsyncAnnotateFileResponse(proto.Message): + r"""The response for a single offline file annotation request. + + Attributes: + output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): + The output location and metadata from + AsyncAnnotateFileRequest. + """ + + output_config = proto.Field( + proto.MESSAGE, + number=1, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateFilesRequest(proto.Message): + r"""Multiple async file annotation requests are batched into a + single service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]): + Required. Individual async file annotation + requests for this batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileRequest', + ) + + +class AsyncBatchAnnotateFilesResponse(proto.Message): + r"""Response to an async batch file annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileResponse]): + The list of file annotation responses, one + for each request in + AsyncBatchAnnotateFilesRequest. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileResponse', + ) + + +class InputConfig(proto.Message): + r"""The desired input location and metadata. + + Attributes: + gcs_source (google.cloud.vision_v1p2beta1.types.GcsSource): + The Google Cloud Storage location to read the + input from. + mime_type (str): + The type of the file. Currently only + "application/pdf" and "image/tiff" are + supported. Wildcards are not supported. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message='GcsSource', + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class OutputConfig(proto.Message): + r"""The desired output location and metadata. + + Attributes: + gcs_destination (google.cloud.vision_v1p2beta1.types.GcsDestination): + The Google Cloud Storage location to write + the output(s) to. + batch_size (int): + The max number of response protos to put into each output + JSON file on GCS. The valid range is [1, 100]. If not + specified, the default value is 20. + + For example, for one pdf file with 100 pages, 100 response + protos will be generated. If ``batch_size`` = 20, then 5 + json files each containing 20 response protos will be + written under the prefix ``gcs_destination``.\ ``uri``. + + Currently, batch_size only applies to GcsDestination, with + potential future support for other output configurations. + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message='GcsDestination', + ) + batch_size = proto.Field( + proto.INT32, + number=2, + ) + + +class GcsSource(proto.Message): + r"""The Google Cloud Storage location where the input will be + read from. + + Attributes: + uri (str): + Google Cloud Storage URI for the input file. + This must only be a GCS object. Wildcards are + not currently supported. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class GcsDestination(proto.Message): + r"""The Google Cloud Storage location where the output will be + written to. + + Attributes: + uri (str): + Google Cloud Storage URI where the results will be stored. + Results will be in JSON format and preceded by its + corresponding input URI. This field can either represent a + single file, or a prefix for multiple outputs. Prefixes must + end in a ``/``. + + Examples: + + - File: gs://bucket-name/filename.json + - Prefix: gs://bucket-name/prefix/here/ + - File: gs://bucket-name/prefix/here + + If multiple outputs, each response is still + AnnotateFileResponse, each of which contains some subset of + the full list of AnnotateImageResponse. Multiple outputs can + happen if, for example, the output JSON is too large and + overflows into multiple sharded files. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class OperationMetadata(proto.Message): + r"""Contains metadata for the BatchAnnotateImages operation. + + Attributes: + state (google.cloud.vision_v1p2beta1.types.OperationMetadata.State): + Current state of the batch operation. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was received. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the operation result was last + updated. + """ + class State(proto.Enum): + r"""Batch operation states.""" + STATE_UNSPECIFIED = 0 + CREATED = 1 + RUNNING = 2 + DONE = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py new file mode 100644 index 00000000..96da0434 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py @@ -0,0 +1,393 @@ +# -*- 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.vision_v1p2beta1.types import geometry + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p2beta1', + manifest={ + 'TextAnnotation', + 'Page', + 'Block', + 'Paragraph', + 'Word', + 'Symbol', + }, +) + + +class TextAnnotation(proto.Message): + r"""TextAnnotation contains a structured representation of OCR extracted + text. The hierarchy of an OCR extracted text structure is like this: + TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each + structural component, starting from Page, may further have their own + properties. Properties describe detected languages, breaks etc.. + Please refer to the + [TextAnnotation.TextProperty][google.cloud.vision.v1p2beta1.TextAnnotation.TextProperty] + message definition below for more detail. + + Attributes: + pages (Sequence[google.cloud.vision_v1p2beta1.types.Page]): + List of pages detected by OCR. + text (str): + UTF-8 text detected on the pages. + """ + + 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, + ) + + class DetectedBreak(proto.Message): + r"""Detected start or end of a structural component. + + Attributes: + type_ (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak.BreakType): + Detected break type. + is_prefix (bool): + True if break prepends the element. + """ + class BreakType(proto.Enum): + r"""Enum to denote the type of break found. New line, space etc.""" + UNKNOWN = 0 + SPACE = 1 + SURE_SPACE = 2 + EOL_SURE_SPACE = 3 + HYPHEN = 4 + LINE_BREAK = 5 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='TextAnnotation.DetectedBreak.BreakType', + ) + is_prefix = proto.Field( + proto.BOOL, + number=2, + ) + + class TextProperty(proto.Message): + r"""Additional information detected on the structural component. + + Attributes: + detected_languages (Sequence[google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedLanguage]): + A list of detected languages together with + confidence. + detected_break (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak): + Detected start or end of a text segment. + """ + + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='TextAnnotation.DetectedLanguage', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='TextAnnotation.DetectedBreak', + ) + + pages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Page', + ) + text = proto.Field( + proto.STRING, + number=2, + ) + + +class Page(proto.Message): + r"""Detected page from OCR. + + Attributes: + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): + Additional information detected on the page. + width (int): + Page width. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + height (int): + Page height. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + blocks (Sequence[google.cloud.vision_v1p2beta1.types.Block]): + List of blocks of text, images etc on this + page. + confidence (float): + Confidence of the OCR results on the page. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + width = proto.Field( + proto.INT32, + number=2, + ) + height = proto.Field( + proto.INT32, + number=3, + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Block', + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Block(proto.Message): + r"""Logical element on the page. + + Attributes: + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + block. + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The bounding box for the block. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: + + :: + + 0----1 + | | + 3----2 + + - when it's rotated 180 degrees around the top-left corner + it becomes: + + :: + + 2----3 + | | + 1----0 + + and the vertice order will still be (0, 1, 2, 3). + paragraphs (Sequence[google.cloud.vision_v1p2beta1.types.Paragraph]): + List of paragraphs in this block (if this + blocks is of type text). + block_type (google.cloud.vision_v1p2beta1.types.Block.BlockType): + Detected block type (text, image etc) for + this block. + confidence (float): + Confidence of the OCR results on the block. Range [0, 1]. + """ + class BlockType(proto.Enum): + r"""Type of a block (text, image etc) as identified by OCR.""" + UNKNOWN = 0 + TEXT = 1 + TABLE = 2 + PICTURE = 3 + RULER = 4 + BARCODE = 5 + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Paragraph', + ) + block_type = proto.Field( + proto.ENUM, + number=4, + enum=BlockType, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Paragraph(proto.Message): + r"""Structural unit of text representing a number of words in + certain order. + + Attributes: + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + paragraph. + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The bounding box for the paragraph. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + words (Sequence[google.cloud.vision_v1p2beta1.types.Word]): + List of words in this paragraph. + confidence (float): + Confidence of the OCR results for the paragraph. Range [0, + 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + words = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Word', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Word(proto.Message): + r"""A word representation. + + Attributes: + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): + Additional information detected for the word. + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The bounding box for the word. The vertices are in the order + of top-left, top-right, bottom-right, bottom-left. When a + rotation of the bounding box is detected the rotation is + represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + symbols (Sequence[google.cloud.vision_v1p2beta1.types.Symbol]): + List of symbols in the word. + The order of the symbols follows the natural + reading order. + confidence (float): + Confidence of the OCR results for the word. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + symbols = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Symbol', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Symbol(proto.Message): + r"""A single symbol representation. + + Attributes: + property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + symbol. + bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): + The bounding box for the symbol. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + text (str): + The actual UTF-8 representation of the + symbol. + confidence (float): + Confidence of the OCR results for the symbol. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + text = proto.Field( + proto.STRING, + number=3, + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py new file mode 100644 index 00000000..0f5fbefd --- /dev/null +++ b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py @@ -0,0 +1,199 @@ +# -*- 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.vision.v1p2beta1', + manifest={ + 'WebDetection', + }, +) + + +class WebDetection(proto.Message): + r"""Relevant information for the image from the Internet. + + Attributes: + web_entities (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebEntity]): + Deduced entities from similar images on the + Internet. + full_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): + Fully matching images from the Internet. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): + Partial matching images from the Internet. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + pages_with_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebPage]): + Web pages containing the matching images from + the Internet. + visually_similar_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): + The visually similar image results. + best_guess_labels (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebLabel]): + Best guess text labels for the request image. + """ + + class WebEntity(proto.Message): + r"""Entity deduced from similar images on the Internet. + + Attributes: + entity_id (str): + Opaque entity ID. + score (float): + Overall relevancy score for the entity. + Not normalized and not comparable across + different image queries. + description (str): + Canonical description of the entity, in + English. + """ + + entity_id = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + + class WebImage(proto.Message): + r"""Metadata for online images. + + Attributes: + url (str): + The result image URL. + score (float): + (Deprecated) Overall relevancy score for the + image. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + + class WebPage(proto.Message): + r"""Metadata for web pages. + + Attributes: + url (str): + The result web page URL. + score (float): + (Deprecated) Overall relevancy score for the + web page. + page_title (str): + Title for the web page, may contain HTML + markups. + full_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): + Fully matching images on the page. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): + Partial matching images on the page. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + page_title = proto.Field( + proto.STRING, + number=3, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='WebDetection.WebImage', + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='WebDetection.WebImage', + ) + + class WebLabel(proto.Message): + r"""Label to provide extra metadata for the web detection. + + Attributes: + label (str): + Label for extra metadata. + language_code (str): + The BCP-47 language code for ``label``, such as "en-US" or + "sr-Latn". For more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + """ + + label = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + + web_entities = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=WebEntity, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=WebImage, + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=WebImage, + ) + pages_with_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=WebPage, + ) + visually_similar_images = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=WebImage, + ) + best_guess_labels = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=WebLabel, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/mypy.ini b/owl-bot-staging/v1p2beta1/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1p2beta1/noxfile.py b/owl-bot-staging/v1p2beta1/noxfile.py new file mode 100644 index 00000000..d8e69c5f --- /dev/null +++ b/owl-bot-staging/v1p2beta1/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/vision_v1p2beta1/', + '--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/v1p2beta1/scripts/fixup_vision_v1p2beta1_keywords.py b/owl-bot-staging/v1p2beta1/scripts/fixup_vision_v1p2beta1_keywords.py new file mode 100644 index 00000000..bae0aa90 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/scripts/fixup_vision_v1p2beta1_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 visionCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'async_batch_annotate_files': ('requests', ), + 'batch_annotate_images': ('requests', ), + } + + 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: a.keyword.value not 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=visionCallTransformer(), +): + """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 vision 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/v1p2beta1/setup.py b/owl-bot-staging/v1p2beta1/setup.py new file mode 100644 index 00000000..9d03e702 --- /dev/null +++ b/owl-bot-staging/v1p2beta1/setup.py @@ -0,0 +1,54 @@ +# -*- 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-vision', + 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, < 3.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', + 'Programming Language :: Python :: 3.9', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1p2beta1/tests/__init__.py b/owl-bot-staging/v1p2beta1/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p2beta1/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/v1p2beta1/tests/unit/__init__.py b/owl-bot-staging/v1p2beta1/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p2beta1/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/v1p2beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p2beta1/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p2beta1/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/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__init__.py b/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__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/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py new file mode 100644 index 00000000..1af6142e --- /dev/null +++ b/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py @@ -0,0 +1,1341 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1p2beta1.services.image_annotator import ImageAnnotatorAsyncClient +from google.cloud.vision_v1p2beta1.services.image_annotator import ImageAnnotatorClient +from google.cloud.vision_v1p2beta1.services.image_annotator import transports +from google.cloud.vision_v1p2beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1p2beta1.types import image_annotator +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ImageAnnotatorGrpcTransport, "grpc"), + (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +def test_image_annotator_client_get_transport_class(): + transport = ImageAnnotatorClient.get_transport_class() + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports + + transport = ImageAnnotatorClient.get_transport_class("grpc") + assert transport == transports.ImageAnnotatorGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + +def test_image_annotator_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ImageAnnotatorClient( + 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, + always_use_jwt_access=True, + ) + + +def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse( + ) + response = client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +def test_batch_annotate_images_from_dict(): + test_batch_annotate_images(request_type=dict) + + +def test_batch_annotate_images_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 = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + client.batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( + )) + response = await client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async_from_dict(): + await test_batch_annotate_images_async(request_type=dict) + + +def test_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +def test_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_async_batch_annotate_files_from_dict(): + test_async_batch_annotate_files(request_type=dict) + + +def test_async_batch_annotate_files_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 = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + client.async_batch_annotate_files() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files), + '__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.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async_from_dict(): + await test_async_batch_annotate_files_async(request_type=dict) + + +def test_async_batch_annotate_files_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +def test_async_batch_annotate_files_flattened_error(): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ImageAnnotatorClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, +]) +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 = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ImageAnnotatorGrpcTransport, + ) + +def test_image_annotator_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_image_annotator_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'batch_annotate_images', + 'async_batch_annotate_files', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ImageAnnotatorGrpcTransport, grpc_helpers), + (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_image_annotator_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_host_no_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_image_annotator_host_with_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_image_annotator_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcTransport( + 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_image_annotator_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_grpc_lro_client(): + client = ImageAnnotatorClient( + 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_image_annotator_grpc_lro_async_client(): + client = ImageAnnotatorAsyncClient( + 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 = ImageAnnotatorClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ImageAnnotatorClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = ImageAnnotatorClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ImageAnnotatorClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ImageAnnotatorClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ImageAnnotatorClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = ImageAnnotatorClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ImageAnnotatorClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ImageAnnotatorClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + transport_class = ImageAnnotatorClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1p3beta1/.coveragerc b/owl-bot-staging/v1p3beta1/.coveragerc new file mode 100644 index 00000000..75747063 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/vision/__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/v1p3beta1/MANIFEST.in b/owl-bot-staging/v1p3beta1/MANIFEST.in new file mode 100644 index 00000000..5c6705a2 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/vision *.py +recursive-include google/cloud/vision_v1p3beta1 *.py diff --git a/owl-bot-staging/v1p3beta1/README.rst b/owl-bot-staging/v1p3beta1/README.rst new file mode 100644 index 00000000..39f9ca72 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Vision 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 Vision 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/v1p3beta1/docs/conf.py b/owl-bot-staging/v1p3beta1/docs/conf.py new file mode 100644 index 00000000..6e730bf5 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/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-vision 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-vision" +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-vision-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-vision.tex", + u"google-cloud-vision 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-vision", + u"Google Cloud Vision 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-vision", + u"google-cloud-vision Documentation", + author, + "google-cloud-vision", + "GAPIC library for Google Cloud Vision 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/v1p3beta1/docs/index.rst b/owl-bot-staging/v1p3beta1/docs/index.rst new file mode 100644 index 00000000..87acf3ca --- /dev/null +++ b/owl-bot-staging/v1p3beta1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + vision_v1p3beta1/services + vision_v1p3beta1/types diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst new file mode 100644 index 00000000..a5ed7542 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p3beta1.services.image_annotator + :members: + :inherited-members: diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst new file mode 100644 index 00000000..21e79602 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst @@ -0,0 +1,10 @@ +ProductSearch +------------------------------- + +.. automodule:: google.cloud.vision_v1p3beta1.services.product_search + :members: + :inherited-members: + +.. automodule:: google.cloud.vision_v1p3beta1.services.product_search.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst new file mode 100644 index 00000000..06da9b3d --- /dev/null +++ b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst @@ -0,0 +1,7 @@ +Services for Google Cloud Vision v1p3beta1 API +============================================== +.. toctree:: + :maxdepth: 2 + + image_annotator + product_search diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst new file mode 100644 index 00000000..5fdbaea1 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Vision v1p3beta1 API +=========================================== + +.. automodule:: google.cloud.vision_v1p3beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py new file mode 100644 index 00000000..f3be6b83 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py @@ -0,0 +1,187 @@ +# -*- 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.vision_v1p3beta1.services.image_annotator.client import ImageAnnotatorClient +from google.cloud.vision_v1p3beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient +from google.cloud.vision_v1p3beta1.services.product_search.client import ProductSearchClient +from google.cloud.vision_v1p3beta1.services.product_search.async_client import ProductSearchAsyncClient + +from google.cloud.vision_v1p3beta1.types.geometry import BoundingPoly +from google.cloud.vision_v1p3beta1.types.geometry import NormalizedBoundingPoly +from google.cloud.vision_v1p3beta1.types.geometry import NormalizedVertex +from google.cloud.vision_v1p3beta1.types.geometry import Position +from google.cloud.vision_v1p3beta1.types.geometry import Vertex +from google.cloud.vision_v1p3beta1.types.image_annotator import AnnotateFileResponse +from google.cloud.vision_v1p3beta1.types.image_annotator import AnnotateImageRequest +from google.cloud.vision_v1p3beta1.types.image_annotator import AnnotateImageResponse +from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncAnnotateFileRequest +from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncAnnotateFileResponse +from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncBatchAnnotateFilesRequest +from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncBatchAnnotateFilesResponse +from google.cloud.vision_v1p3beta1.types.image_annotator import BatchAnnotateImagesRequest +from google.cloud.vision_v1p3beta1.types.image_annotator import BatchAnnotateImagesResponse +from google.cloud.vision_v1p3beta1.types.image_annotator import ColorInfo +from google.cloud.vision_v1p3beta1.types.image_annotator import CropHint +from google.cloud.vision_v1p3beta1.types.image_annotator import CropHintsAnnotation +from google.cloud.vision_v1p3beta1.types.image_annotator import CropHintsParams +from google.cloud.vision_v1p3beta1.types.image_annotator import DominantColorsAnnotation +from google.cloud.vision_v1p3beta1.types.image_annotator import EntityAnnotation +from google.cloud.vision_v1p3beta1.types.image_annotator import FaceAnnotation +from google.cloud.vision_v1p3beta1.types.image_annotator import Feature +from google.cloud.vision_v1p3beta1.types.image_annotator import GcsDestination +from google.cloud.vision_v1p3beta1.types.image_annotator import GcsSource +from google.cloud.vision_v1p3beta1.types.image_annotator import Image +from google.cloud.vision_v1p3beta1.types.image_annotator import ImageAnnotationContext +from google.cloud.vision_v1p3beta1.types.image_annotator import ImageContext +from google.cloud.vision_v1p3beta1.types.image_annotator import ImageProperties +from google.cloud.vision_v1p3beta1.types.image_annotator import ImageSource +from google.cloud.vision_v1p3beta1.types.image_annotator import InputConfig +from google.cloud.vision_v1p3beta1.types.image_annotator import LatLongRect +from google.cloud.vision_v1p3beta1.types.image_annotator import LocalizedObjectAnnotation +from google.cloud.vision_v1p3beta1.types.image_annotator import LocationInfo +from google.cloud.vision_v1p3beta1.types.image_annotator import OperationMetadata +from google.cloud.vision_v1p3beta1.types.image_annotator import OutputConfig +from google.cloud.vision_v1p3beta1.types.image_annotator import Property +from google.cloud.vision_v1p3beta1.types.image_annotator import SafeSearchAnnotation +from google.cloud.vision_v1p3beta1.types.image_annotator import TextDetectionParams +from google.cloud.vision_v1p3beta1.types.image_annotator import WebDetectionParams +from google.cloud.vision_v1p3beta1.types.image_annotator import Likelihood +from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchParams +from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchResults +from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchCategory +from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchResultsView +from google.cloud.vision_v1p3beta1.types.product_search_service import AddProductToProductSetRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import BatchOperationMetadata +from google.cloud.vision_v1p3beta1.types.product_search_service import CreateProductRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import CreateProductSetRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import CreateReferenceImageRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import DeleteProductRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import DeleteProductSetRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import DeleteReferenceImageRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import GetProductRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import GetProductSetRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import GetReferenceImageRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsGcsSource +from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsInputConfig +from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsResponse +from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductSetsRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductSetsResponse +from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsInProductSetRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsInProductSetResponse +from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsResponse +from google.cloud.vision_v1p3beta1.types.product_search_service import ListReferenceImagesRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import ListReferenceImagesResponse +from google.cloud.vision_v1p3beta1.types.product_search_service import Product +from google.cloud.vision_v1p3beta1.types.product_search_service import ProductSet +from google.cloud.vision_v1p3beta1.types.product_search_service import ReferenceImage +from google.cloud.vision_v1p3beta1.types.product_search_service import RemoveProductFromProductSetRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import UpdateProductRequest +from google.cloud.vision_v1p3beta1.types.product_search_service import UpdateProductSetRequest +from google.cloud.vision_v1p3beta1.types.text_annotation import Block +from google.cloud.vision_v1p3beta1.types.text_annotation import Page +from google.cloud.vision_v1p3beta1.types.text_annotation import Paragraph +from google.cloud.vision_v1p3beta1.types.text_annotation import Symbol +from google.cloud.vision_v1p3beta1.types.text_annotation import TextAnnotation +from google.cloud.vision_v1p3beta1.types.text_annotation import Word +from google.cloud.vision_v1p3beta1.types.web_detection import WebDetection + +__all__ = ('ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', + 'ProductSearchClient', + 'ProductSearchAsyncClient', + 'BoundingPoly', + 'NormalizedBoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocalizedObjectAnnotation', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'ProductSearchParams', + 'ProductSearchResults', + 'ProductSearchCategory', + 'ProductSearchResultsView', + 'AddProductToProductSetRequest', + 'BatchOperationMetadata', + 'CreateProductRequest', + 'CreateProductSetRequest', + 'CreateReferenceImageRequest', + 'DeleteProductRequest', + 'DeleteProductSetRequest', + 'DeleteReferenceImageRequest', + 'GetProductRequest', + 'GetProductSetRequest', + 'GetReferenceImageRequest', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ListProductsRequest', + 'ListProductsResponse', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'Product', + 'ProductSet', + 'ReferenceImage', + 'RemoveProductFromProductSetRequest', + 'UpdateProductRequest', + 'UpdateProductSetRequest', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py new file mode 100644 index 00000000..db381a13 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py @@ -0,0 +1,188 @@ +# -*- 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.image_annotator import ImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient +from .services.product_search import ProductSearchClient +from .services.product_search import ProductSearchAsyncClient + +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedBoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Position +from .types.geometry import Vertex +from .types.image_annotator import AnnotateFileResponse +from .types.image_annotator import AnnotateImageRequest +from .types.image_annotator import AnnotateImageResponse +from .types.image_annotator import AsyncAnnotateFileRequest +from .types.image_annotator import AsyncAnnotateFileResponse +from .types.image_annotator import AsyncBatchAnnotateFilesRequest +from .types.image_annotator import AsyncBatchAnnotateFilesResponse +from .types.image_annotator import BatchAnnotateImagesRequest +from .types.image_annotator import BatchAnnotateImagesResponse +from .types.image_annotator import ColorInfo +from .types.image_annotator import CropHint +from .types.image_annotator import CropHintsAnnotation +from .types.image_annotator import CropHintsParams +from .types.image_annotator import DominantColorsAnnotation +from .types.image_annotator import EntityAnnotation +from .types.image_annotator import FaceAnnotation +from .types.image_annotator import Feature +from .types.image_annotator import GcsDestination +from .types.image_annotator import GcsSource +from .types.image_annotator import Image +from .types.image_annotator import ImageAnnotationContext +from .types.image_annotator import ImageContext +from .types.image_annotator import ImageProperties +from .types.image_annotator import ImageSource +from .types.image_annotator import InputConfig +from .types.image_annotator import LatLongRect +from .types.image_annotator import LocalizedObjectAnnotation +from .types.image_annotator import LocationInfo +from .types.image_annotator import OperationMetadata +from .types.image_annotator import OutputConfig +from .types.image_annotator import Property +from .types.image_annotator import SafeSearchAnnotation +from .types.image_annotator import TextDetectionParams +from .types.image_annotator import WebDetectionParams +from .types.image_annotator import Likelihood +from .types.product_search import ProductSearchParams +from .types.product_search import ProductSearchResults +from .types.product_search import ProductSearchCategory +from .types.product_search import ProductSearchResultsView +from .types.product_search_service import AddProductToProductSetRequest +from .types.product_search_service import BatchOperationMetadata +from .types.product_search_service import CreateProductRequest +from .types.product_search_service import CreateProductSetRequest +from .types.product_search_service import CreateReferenceImageRequest +from .types.product_search_service import DeleteProductRequest +from .types.product_search_service import DeleteProductSetRequest +from .types.product_search_service import DeleteReferenceImageRequest +from .types.product_search_service import GetProductRequest +from .types.product_search_service import GetProductSetRequest +from .types.product_search_service import GetReferenceImageRequest +from .types.product_search_service import ImportProductSetsGcsSource +from .types.product_search_service import ImportProductSetsInputConfig +from .types.product_search_service import ImportProductSetsRequest +from .types.product_search_service import ImportProductSetsResponse +from .types.product_search_service import ListProductSetsRequest +from .types.product_search_service import ListProductSetsResponse +from .types.product_search_service import ListProductsInProductSetRequest +from .types.product_search_service import ListProductsInProductSetResponse +from .types.product_search_service import ListProductsRequest +from .types.product_search_service import ListProductsResponse +from .types.product_search_service import ListReferenceImagesRequest +from .types.product_search_service import ListReferenceImagesResponse +from .types.product_search_service import Product +from .types.product_search_service import ProductSet +from .types.product_search_service import ReferenceImage +from .types.product_search_service import RemoveProductFromProductSetRequest +from .types.product_search_service import UpdateProductRequest +from .types.product_search_service import UpdateProductSetRequest +from .types.text_annotation import Block +from .types.text_annotation import Page +from .types.text_annotation import Paragraph +from .types.text_annotation import Symbol +from .types.text_annotation import TextAnnotation +from .types.text_annotation import Word +from .types.web_detection import WebDetection + +__all__ = ( + 'ImageAnnotatorAsyncClient', + 'ProductSearchAsyncClient', +'AddProductToProductSetRequest', +'AnnotateFileResponse', +'AnnotateImageRequest', +'AnnotateImageResponse', +'AsyncAnnotateFileRequest', +'AsyncAnnotateFileResponse', +'AsyncBatchAnnotateFilesRequest', +'AsyncBatchAnnotateFilesResponse', +'BatchAnnotateImagesRequest', +'BatchAnnotateImagesResponse', +'BatchOperationMetadata', +'Block', +'BoundingPoly', +'ColorInfo', +'CreateProductRequest', +'CreateProductSetRequest', +'CreateReferenceImageRequest', +'CropHint', +'CropHintsAnnotation', +'CropHintsParams', +'DeleteProductRequest', +'DeleteProductSetRequest', +'DeleteReferenceImageRequest', +'DominantColorsAnnotation', +'EntityAnnotation', +'FaceAnnotation', +'Feature', +'GcsDestination', +'GcsSource', +'GetProductRequest', +'GetProductSetRequest', +'GetReferenceImageRequest', +'Image', +'ImageAnnotationContext', +'ImageAnnotatorClient', +'ImageContext', +'ImageProperties', +'ImageSource', +'ImportProductSetsGcsSource', +'ImportProductSetsInputConfig', +'ImportProductSetsRequest', +'ImportProductSetsResponse', +'InputConfig', +'LatLongRect', +'Likelihood', +'ListProductSetsRequest', +'ListProductSetsResponse', +'ListProductsInProductSetRequest', +'ListProductsInProductSetResponse', +'ListProductsRequest', +'ListProductsResponse', +'ListReferenceImagesRequest', +'ListReferenceImagesResponse', +'LocalizedObjectAnnotation', +'LocationInfo', +'NormalizedBoundingPoly', +'NormalizedVertex', +'OperationMetadata', +'OutputConfig', +'Page', +'Paragraph', +'Position', +'Product', +'ProductSearchCategory', +'ProductSearchClient', +'ProductSearchParams', +'ProductSearchResults', +'ProductSearchResultsView', +'ProductSet', +'Property', +'ReferenceImage', +'RemoveProductFromProductSetRequest', +'SafeSearchAnnotation', +'Symbol', +'TextAnnotation', +'TextDetectionParams', +'UpdateProductRequest', +'UpdateProductSetRequest', +'Vertex', +'WebDetection', +'WebDetectionParams', +'Word', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json new file mode 100644 index 00000000..a1425044 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json @@ -0,0 +1,237 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.vision_v1p3beta1", + "protoPackage": "google.cloud.vision.v1p3beta1", + "schema": "1.0", + "services": { + "ImageAnnotator": { + "clients": { + "grpc": { + "libraryClient": "ImageAnnotatorClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ImageAnnotatorAsyncClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + } + } + }, + "ProductSearch": { + "clients": { + "grpc": { + "libraryClient": "ProductSearchClient", + "rpcs": { + "AddProductToProductSet": { + "methods": [ + "add_product_to_product_set" + ] + }, + "CreateProduct": { + "methods": [ + "create_product" + ] + }, + "CreateProductSet": { + "methods": [ + "create_product_set" + ] + }, + "CreateReferenceImage": { + "methods": [ + "create_reference_image" + ] + }, + "DeleteProduct": { + "methods": [ + "delete_product" + ] + }, + "DeleteProductSet": { + "methods": [ + "delete_product_set" + ] + }, + "DeleteReferenceImage": { + "methods": [ + "delete_reference_image" + ] + }, + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "GetProductSet": { + "methods": [ + "get_product_set" + ] + }, + "GetReferenceImage": { + "methods": [ + "get_reference_image" + ] + }, + "ImportProductSets": { + "methods": [ + "import_product_sets" + ] + }, + "ListProductSets": { + "methods": [ + "list_product_sets" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + }, + "ListProductsInProductSet": { + "methods": [ + "list_products_in_product_set" + ] + }, + "ListReferenceImages": { + "methods": [ + "list_reference_images" + ] + }, + "RemoveProductFromProductSet": { + "methods": [ + "remove_product_from_product_set" + ] + }, + "UpdateProduct": { + "methods": [ + "update_product" + ] + }, + "UpdateProductSet": { + "methods": [ + "update_product_set" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductSearchAsyncClient", + "rpcs": { + "AddProductToProductSet": { + "methods": [ + "add_product_to_product_set" + ] + }, + "CreateProduct": { + "methods": [ + "create_product" + ] + }, + "CreateProductSet": { + "methods": [ + "create_product_set" + ] + }, + "CreateReferenceImage": { + "methods": [ + "create_reference_image" + ] + }, + "DeleteProduct": { + "methods": [ + "delete_product" + ] + }, + "DeleteProductSet": { + "methods": [ + "delete_product_set" + ] + }, + "DeleteReferenceImage": { + "methods": [ + "delete_reference_image" + ] + }, + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "GetProductSet": { + "methods": [ + "get_product_set" + ] + }, + "GetReferenceImage": { + "methods": [ + "get_reference_image" + ] + }, + "ImportProductSets": { + "methods": [ + "import_product_sets" + ] + }, + "ListProductSets": { + "methods": [ + "list_product_sets" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + }, + "ListProductsInProductSet": { + "methods": [ + "list_products_in_product_set" + ] + }, + "ListReferenceImages": { + "methods": [ + "list_reference_images" + ] + }, + "RemoveProductFromProductSet": { + "methods": [ + "remove_product_from_product_set" + ] + }, + "UpdateProduct": { + "methods": [ + "update_product" + ] + }, + "UpdateProductSet": { + "methods": [ + "update_product_set" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/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/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py new file mode 100644 index 00000000..3cbfa2fa --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__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 ImageAnnotatorClient +from .async_client import ImageAnnotatorAsyncClient + +__all__ = ( + 'ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py new file mode 100644 index 00000000..08b9e34a --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py @@ -0,0 +1,336 @@ +# -*- 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.vision_v1p3beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport +from .client import ImageAnnotatorClient + + +class ImageAnnotatorAsyncClient: + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + _client: ImageAnnotatorClient + + DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT + + product_path = staticmethod(ImageAnnotatorClient.product_path) + parse_product_path = staticmethod(ImageAnnotatorClient.parse_product_path) + product_set_path = staticmethod(ImageAnnotatorClient.product_set_path) + parse_product_set_path = staticmethod(ImageAnnotatorClient.parse_product_set_path) + common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) + parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) + common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) + parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) + common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) + parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) + common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) + parse_common_location_path = staticmethod(ImageAnnotatorClient.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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def batch_annotate_images(self, + request: image_annotator.BatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest`): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]`): + Individual image annotation requests + for this batch. + + 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.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def async_batch_annotate_files(self, + request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest`): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]`): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1p3beta1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorAsyncClient", +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py new file mode 100644 index 00000000..f28deb03 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py @@ -0,0 +1,530 @@ +# -*- 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 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.vision_v1p3beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ImageAnnotatorGrpcTransport +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +class ImageAnnotatorClientMeta(type): + """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] + _transport_registry["grpc"] = ImageAnnotatorGrpcTransport + _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ImageAnnotatorTransport]: + """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + @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 = "vision.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: + ImageAnnotatorClient: 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: + ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(project: str,location: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_set_path(project: str,location: str,product_set: str,) -> str: + """Returns a fully-qualified product_set string.""" + return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + + @staticmethod + def parse_product_set_path(path: str) -> Dict[str,str]: + """Parses a product_set path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?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, ImageAnnotatorTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): + # transport is a ImageAnnotatorTransport 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, + always_use_jwt_access=True, + ) + + def batch_annotate_images(self, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest, dict]): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]): + Individual image annotation requests + for this batch. + + 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.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 image_annotator.BatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): + request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def async_batch_annotate_files(self, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest, dict]): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1p3beta1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 image_annotator.AsyncBatchAnnotateFilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): + request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorClient", +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py new file mode 100644 index 00000000..94f01250 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/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 ImageAnnotatorTransport +from .grpc import ImageAnnotatorGrpcTransport +from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] +_transport_registry['grpc'] = ImageAnnotatorGrpcTransport +_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport + +__all__ = ( + 'ImageAnnotatorTransport', + 'ImageAnnotatorGrpcTransport', + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py new file mode 100644 index 00000000..0e5d068d --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py @@ -0,0 +1,211 @@ +# -*- 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.vision_v1p3beta1.types import image_annotator +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-vision', + ).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 ImageAnnotatorTransport(abc.ABC): + """Abstract transport class for ImageAnnotator.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( + self.batch_annotate_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.async_batch_annotate_files: gapic_v1.method.wrap_method( + self.async_batch_annotate_files, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Union[ + image_annotator.BatchAnnotateImagesResponse, + Awaitable[image_annotator.BatchAnnotateImagesResponse] + ]]: + raise NotImplementedError() + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ImageAnnotatorTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py new file mode 100644 index 00000000..790b47d3 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.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 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.vision_v1p3beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO + + +class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): + """gRPC backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + image_annotator.BatchAnnotateImagesResponse]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + ~.BatchAnnotateImagesResponse]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + operations_pb2.Operation]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + ~.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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ImageAnnotatorGrpcTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py new file mode 100644 index 00000000..aabeb507 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py @@ -0,0 +1,314 @@ +# -*- 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.vision_v1p3beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .grpc import ImageAnnotatorGrpcTransport + + +class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): + """gRPC AsyncIO backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Awaitable[image_annotator.BatchAnnotateImagesResponse]]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + Awaitable[~.BatchAnnotateImagesResponse]]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + 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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__init__.py new file mode 100644 index 00000000..cf79a54d --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__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 ProductSearchClient +from .async_client import ProductSearchAsyncClient + +__all__ = ( + 'ProductSearchClient', + 'ProductSearchAsyncClient', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py new file mode 100644 index 00000000..f9d093b2 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py @@ -0,0 +1,1988 @@ +# -*- 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.vision_v1p3beta1.services.product_search import pagers +from google.cloud.vision_v1p3beta1.types import geometry +from google.cloud.vision_v1p3beta1.types import product_search_service +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport +from .client import ProductSearchClient + + +class ProductSearchAsyncClient: + """Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + """ + + _client: ProductSearchClient + + DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT + + product_path = staticmethod(ProductSearchClient.product_path) + parse_product_path = staticmethod(ProductSearchClient.parse_product_path) + product_set_path = staticmethod(ProductSearchClient.product_set_path) + parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) + reference_image_path = staticmethod(ProductSearchClient.reference_image_path) + parse_reference_image_path = staticmethod(ProductSearchClient.parse_reference_image_path) + common_billing_account_path = staticmethod(ProductSearchClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductSearchClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductSearchClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductSearchClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductSearchClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductSearchClient.parse_common_organization_path) + common_project_path = staticmethod(ProductSearchClient.common_project_path) + parse_common_project_path = staticmethod(ProductSearchClient.parse_common_project_path) + common_location_path = staticmethod(ProductSearchClient.common_location_path) + parse_common_location_path = staticmethod(ProductSearchClient.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: + ProductSearchAsyncClient: The constructed client. + """ + return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, 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: + ProductSearchAsyncClient: The constructed client. + """ + return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductSearchTransport: + """Returns the transport used by the client instance. + + Returns: + ProductSearchTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ProductSearchClient).get_transport_class, type(ProductSearchClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ProductSearchTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product search 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, ~.ProductSearchTransport]): 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 = ProductSearchClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def create_product_set(self, + request: product_search_service.CreateProductSetRequest = None, + *, + parent: str = None, + product_set: product_search_service.ProductSet = None, + product_set_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductSetRequest`): + The request object. Request message for the + `CreateProductSet` method. + parent (:class:`str`): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): + Required. The ProductSet to create. + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set_id (:class:`str`): + A user-supplied resource id for this ProductSet. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_set_id`` 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.vision_v1p3beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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, product_set, product_set_id]) + 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 = product_search_service.CreateProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product_set is not None: + request.product_set = product_set + if product_set_id is not None: + request.product_set_id = product_set_id + + # 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_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def list_product_sets(self, + request: product_search_service.ListProductSetsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductSetsAsyncPager: + r"""Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.ListProductSetsRequest`): + The request object. Request message for the + `ListProductSets` method. + parent (:class:`str`): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.vision_v1p3beta1.services.product_search.pagers.ListProductSetsAsyncPager: + Response message for the ListProductSets method. + + 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 = product_search_service.ListProductSetsRequest(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_product_sets, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductSetsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_product_set(self, + request: product_search_service.GetProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.GetProductSetRequest`): + The request object. Request message for the + `GetProductSet` method. + name (:class:`str`): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p3beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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 = product_search_service.GetProductSetRequest(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.get_product_set, + 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=600.0, + ), + default_timeout=600.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 update_product_set(self, + request: product_search_service.UpdateProductSetRequest = None, + *, + product_set: product_search_service.ProductSet = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest`): + The request object. Request message for the + `UpdateProductSet` method. + product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): + Required. The ProductSet resource + which replaces the one on the server. + + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask path is ``display_name``. + + This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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([product_set, update_mask]) + 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 = product_search_service.UpdateProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_set is not None: + request.product_set = product_set + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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(( + ("product_set.name", request.product_set.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product_set(self, + request: product_search_service.DeleteProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a ProductSet. All Products and + ReferenceImages in the ProductSet will be deleted. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest`): + The request object. Request message for the + `DeleteProductSet` method. + name (:class:`str`): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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. + """ + # 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 = product_search_service.DeleteProductSetRequest(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_product_set, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_product(self, + request: product_search_service.CreateProductRequest = None, + *, + parent: str = None, + product: product_search_service.Product = None, + product_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductRequest`): + The request object. Request message for the + `CreateProduct` method. + parent (:class:`str`): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`google.cloud.vision_v1p3beta1.types.Product`): + Required. The product to create. + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_id (:class:`str`): + A user-supplied resource id for this Product. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_id`` 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.vision_v1p3beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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, product, product_id]) + 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 = product_search_service.CreateProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product is not None: + request.product = product + if product_id is not None: + request.product_id = product_id + + # 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_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def list_products(self, + request: product_search_service.ListProductsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsAsyncPager: + r"""Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsRequest`): + The request object. Request message for the + `ListProducts` method. + parent (:class:`str`): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + + 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.vision_v1p3beta1.services.product_search.pagers.ListProductsAsyncPager: + Response message for the ListProducts method. + + 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 = product_search_service.ListProductsRequest(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_products, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_product(self, + request: product_search_service.GetProductRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.GetProductRequest`): + The request object. Request message for the `GetProduct` + method. + name (:class:`str`): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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.vision_v1p3beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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 = product_search_service.GetProductRequest(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.get_product, + 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=600.0, + ), + default_timeout=600.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 update_product(self, + request: product_search_service.UpdateProductRequest = None, + *, + product: product_search_service.Product = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Makes changes to a Product resource. Only display_name, + description and labels can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductRequest`): + The request object. Request message for the + `UpdateProduct` method. + product (:class:`google.cloud.vision_v1p3beta1.types.Product`): + Required. The Product resource which + replaces the one on the server. + product.name is immutable. + + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask paths include ``product_labels``, ``display_name``, + and ``description``. + + This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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([product, update_mask]) + 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 = product_search_service.UpdateProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product is not None: + request.product = product + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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(( + ("product.name", request.product.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product(self, + request: product_search_service.DeleteProductRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a product and its reference images. + + Metadata of the product and all its images will be deleted right + away, but search queries against ProductSets containing the + product may still work until all related caches are refreshed. + + Possible errors: + + - Returns NOT_FOUND if the product does not exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductRequest`): + The request object. Request message for the + `DeleteProduct` method. + name (:class:`str`): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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. + """ + # 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 = product_search_service.DeleteProductRequest(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_product, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_reference_image(self, + request: product_search_service.CreateReferenceImageRequest = None, + *, + parent: str = None, + reference_image: product_search_service.ReferenceImage = None, + reference_image_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest`): + The request object. Request message for the + `CreateReferenceImage` method. + parent (:class:`str`): + Required. Resource name of the product in which to + create the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image (:class:`google.cloud.vision_v1p3beta1.types.ReferenceImage`): + Required. The reference image to + create. If an image ID is specified, it + is ignored. + + This corresponds to the ``reference_image`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image_id (:class:`str`): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value + as the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``reference_image_id`` 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.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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, reference_image, reference_image_id]) + 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 = product_search_service.CreateReferenceImageRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reference_image is not None: + request.reference_image = reference_image + if reference_image_id is not None: + request.reference_image_id = reference_image_id + + # 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_reference_image, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def delete_reference_image(self, + request: product_search_service.DeleteReferenceImageRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a reference image. + + The image metadata will be deleted right away, but search + queries against ProductSets containing the image may still work + until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the reference image does not exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest`): + The request object. Request message for the + `DeleteReferenceImage` method. + name (:class:`str`): + Required. The resource name of the reference image to + delete. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + + 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. + """ + # 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 = product_search_service.DeleteReferenceImageRequest(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_reference_image, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_reference_images(self, + request: product_search_service.ListReferenceImagesRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReferenceImagesAsyncPager: + r"""Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest`): + The request object. Request message for the + `ListReferenceImages` method. + parent (:class:`str`): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + 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.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: + Response message for the ListReferenceImages method. + + 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 = product_search_service.ListReferenceImagesRequest(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_reference_images, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListReferenceImagesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_reference_image(self, + request: product_search_service.GetReferenceImageRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest`): + The request object. Request message for the + `GetReferenceImage` method. + name (:class:`str`): + Required. The resource name of the ReferenceImage to + get. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + 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.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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 = product_search_service.GetReferenceImageRequest(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.get_reference_image, + 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=600.0, + ), + default_timeout=600.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 add_product_to_product_set(self, + request: product_search_service.AddProductToProductSetRequest = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest`): + The request object. Request message for the + `AddProductToProductSet` method. + name (:class:`str`): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`str`): + Required. The resource name for the Product to be added + to this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 = product_search_service.AddProductToProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_product_to_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def remove_product_from_product_set(self, + request: product_search_service.RemoveProductFromProductSetRequest = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Removes a Product from the specified ProductSet. + + Possible errors: + + - Returns NOT_FOUND If the Product is not found under the + ProductSet. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest`): + The request object. Request message for the + `RemoveProductFromProductSet` method. + name (:class:`str`): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`str`): + Required. The resource name for the Product to be + removed from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 = product_search_service.RemoveProductFromProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.remove_product_from_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_products_in_product_set(self, + request: product_search_service.ListProductsInProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsInProductSetAsyncPager: + r"""Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest`): + The request object. Request message for the + `ListProductsInProductSet` method. + name (:class:`str`): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: + Response message for the ListProductsInProductSet + method. + + 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([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 = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsInProductSetAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def import_product_sets(self, + request: product_search_service.ImportProductSetsRequest = None, + *, + parent: str = None, + input_config: product_search_service.ImportProductSetsInputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Args: + request (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest`): + The request object. Request message for the + `ImportProductSets` method. + parent (:class:`str`): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_config (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig`): + Required. The input content for the + list of requests. + + This corresponds to the ``input_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.vision_v1p3beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + """ + # 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, input_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 = product_search_service.ImportProductSetsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if input_config is not None: + request.input_config = input_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.import_product_sets, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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, + product_search_service.ImportProductSetsResponse, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ProductSearchAsyncClient", +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py new file mode 100644 index 00000000..ad053367 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py @@ -0,0 +1,2093 @@ +# -*- 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 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.vision_v1p3beta1.services.product_search import pagers +from google.cloud.vision_v1p3beta1.types import geometry +from google.cloud.vision_v1p3beta1.types import product_search_service +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductSearchGrpcTransport +from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport + + +class ProductSearchClientMeta(type): + """Metaclass for the ProductSearch 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[ProductSearchTransport]] + _transport_registry["grpc"] = ProductSearchGrpcTransport + _transport_registry["grpc_asyncio"] = ProductSearchGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ProductSearchTransport]: + """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 ProductSearchClient(metaclass=ProductSearchClientMeta): + """Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + """ + + @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 = "vision.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: + ProductSearchClient: 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: + ProductSearchClient: 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) -> ProductSearchTransport: + """Returns the transport used by the client instance. + + Returns: + ProductSearchTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(project: str,location: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_set_path(project: str,location: str,product_set: str,) -> str: + """Returns a fully-qualified product_set string.""" + return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + + @staticmethod + def parse_product_set_path(path: str) -> Dict[str,str]: + """Parses a product_set path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def reference_image_path(project: str,location: str,product: str,reference_image: str,) -> str: + """Returns a fully-qualified reference_image string.""" + return "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) + + @staticmethod + def parse_reference_image_path(path: str) -> Dict[str,str]: + """Parses a reference_image path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)/referenceImages/(?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, ProductSearchTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product search 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, ProductSearchTransport]): 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, ProductSearchTransport): + # transport is a ProductSearchTransport 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, + always_use_jwt_access=True, + ) + + def create_product_set(self, + request: Union[product_search_service.CreateProductSetRequest, dict] = None, + *, + parent: str = None, + product_set: product_search_service.ProductSet = None, + product_set_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.CreateProductSetRequest, dict]): + The request object. Request message for the + `CreateProductSet` method. + parent (str): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): + Required. The ProductSet to create. + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set_id (str): + A user-supplied resource id for this ProductSet. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_set_id`` 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.vision_v1p3beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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, product_set, product_set_id]) + 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 product_search_service.CreateProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateProductSetRequest): + request = product_search_service.CreateProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product_set is not None: + request.product_set = product_set + if product_set_id is not None: + request.product_set_id = product_set_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_product_set] + + # 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_product_sets(self, + request: Union[product_search_service.ListProductSetsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductSetsPager: + r"""Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.ListProductSetsRequest, dict]): + The request object. Request message for the + `ListProductSets` method. + parent (str): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.vision_v1p3beta1.services.product_search.pagers.ListProductSetsPager: + Response message for the ListProductSets method. + + 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 product_search_service.ListProductSetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductSetsRequest): + request = product_search_service.ListProductSetsRequest(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_product_sets] + + # 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.ListProductSetsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_product_set(self, + request: Union[product_search_service.GetProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.GetProductSetRequest, dict]): + The request object. Request message for the + `GetProductSet` method. + name (str): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p3beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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 product_search_service.GetProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetProductSetRequest): + request = product_search_service.GetProductSetRequest(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.get_product_set] + + # 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 update_product_set(self, + request: Union[product_search_service.UpdateProductSetRequest, dict] = None, + *, + product_set: product_search_service.ProductSet = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest, dict]): + The request object. Request message for the + `UpdateProductSet` method. + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): + Required. The ProductSet resource + which replaces the one on the server. + + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask path is ``display_name``. + + This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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([product_set, update_mask]) + 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 product_search_service.UpdateProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.UpdateProductSetRequest): + request = product_search_service.UpdateProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_set is not None: + request.product_set = product_set + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product_set] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product_set(self, + request: Union[product_search_service.DeleteProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a ProductSet. All Products and + ReferenceImages in the ProductSet will be deleted. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest, dict]): + The request object. Request message for the + `DeleteProductSet` method. + name (str): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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. + """ + # 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 product_search_service.DeleteProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteProductSetRequest): + request = product_search_service.DeleteProductSetRequest(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_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_product(self, + request: Union[product_search_service.CreateProductRequest, dict] = None, + *, + parent: str = None, + product: product_search_service.Product = None, + product_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.CreateProductRequest, dict]): + The request object. Request message for the + `CreateProduct` method. + parent (str): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (google.cloud.vision_v1p3beta1.types.Product): + Required. The product to create. + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_id (str): + A user-supplied resource id for this Product. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_id`` 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.vision_v1p3beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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, product, product_id]) + 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 product_search_service.CreateProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateProductRequest): + request = product_search_service.CreateProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product is not None: + request.product = product + if product_id is not None: + request.product_id = product_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_product] + + # 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_products(self, + request: Union[product_search_service.ListProductsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsPager: + r"""Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.ListProductsRequest, dict]): + The request object. Request message for the + `ListProducts` method. + parent (str): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + + 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.vision_v1p3beta1.services.product_search.pagers.ListProductsPager: + Response message for the ListProducts method. + + 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 product_search_service.ListProductsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductsRequest): + request = product_search_service.ListProductsRequest(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_products] + + # 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.ListProductsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_product(self, + request: Union[product_search_service.GetProductRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.GetProductRequest, dict]): + The request object. Request message for the `GetProduct` + method. + name (str): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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.vision_v1p3beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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 product_search_service.GetProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetProductRequest): + request = product_search_service.GetProductRequest(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.get_product] + + # 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 update_product(self, + request: Union[product_search_service.UpdateProductRequest, dict] = None, + *, + product: product_search_service.Product = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Makes changes to a Product resource. Only display_name, + description and labels can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductRequest, dict]): + The request object. Request message for the + `UpdateProduct` method. + product (google.cloud.vision_v1p3beta1.types.Product): + Required. The Product resource which + replaces the one on the server. + product.name is immutable. + + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask paths include ``product_labels``, ``display_name``, + and ``description``. + + This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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([product, update_mask]) + 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 product_search_service.UpdateProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.UpdateProductRequest): + request = product_search_service.UpdateProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product is not None: + request.product = product + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product(self, + request: Union[product_search_service.DeleteProductRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a product and its reference images. + + Metadata of the product and all its images will be deleted right + away, but search queries against ProductSets containing the + product may still work until all related caches are refreshed. + + Possible errors: + + - Returns NOT_FOUND if the product does not exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductRequest, dict]): + The request object. Request message for the + `DeleteProduct` method. + name (str): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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. + """ + # 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 product_search_service.DeleteProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteProductRequest): + request = product_search_service.DeleteProductRequest(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_product] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_reference_image(self, + request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, + *, + parent: str = None, + reference_image: product_search_service.ReferenceImage = None, + reference_image_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest, dict]): + The request object. Request message for the + `CreateReferenceImage` method. + parent (str): + Required. Resource name of the product in which to + create the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image (google.cloud.vision_v1p3beta1.types.ReferenceImage): + Required. The reference image to + create. If an image ID is specified, it + is ignored. + + This corresponds to the ``reference_image`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image_id (str): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value + as the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``reference_image_id`` 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.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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, reference_image, reference_image_id]) + 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 product_search_service.CreateReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateReferenceImageRequest): + request = product_search_service.CreateReferenceImageRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reference_image is not None: + request.reference_image = reference_image + if reference_image_id is not None: + request.reference_image_id = reference_image_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_reference_image] + + # 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_reference_image(self, + request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a reference image. + + The image metadata will be deleted right away, but search + queries against ProductSets containing the image may still work + until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the reference image does not exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest, dict]): + The request object. Request message for the + `DeleteReferenceImage` method. + name (str): + Required. The resource name of the reference image to + delete. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + + 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. + """ + # 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 product_search_service.DeleteReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteReferenceImageRequest): + request = product_search_service.DeleteReferenceImageRequest(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_reference_image] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_reference_images(self, + request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReferenceImagesPager: + r"""Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest, dict]): + The request object. Request message for the + `ListReferenceImages` method. + parent (str): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + 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.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesPager: + Response message for the ListReferenceImages method. + + 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 product_search_service.ListReferenceImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListReferenceImagesRequest): + request = product_search_service.ListReferenceImagesRequest(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_reference_images] + + # 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.ListReferenceImagesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_reference_image(self, + request: Union[product_search_service.GetReferenceImageRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest, dict]): + The request object. Request message for the + `GetReferenceImage` method. + name (str): + Required. The resource name of the ReferenceImage to + get. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + 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.vision_v1p3beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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 product_search_service.GetReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetReferenceImageRequest): + request = product_search_service.GetReferenceImageRequest(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.get_reference_image] + + # 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 add_product_to_product_set(self, + request: Union[product_search_service.AddProductToProductSetRequest, dict] = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest, dict]): + The request object. Request message for the + `AddProductToProductSet` method. + name (str): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (str): + Required. The resource name for the Product to be added + to this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 product_search_service.AddProductToProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.AddProductToProductSetRequest): + request = product_search_service.AddProductToProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_product_to_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def remove_product_from_product_set(self, + request: Union[product_search_service.RemoveProductFromProductSetRequest, dict] = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Removes a Product from the specified ProductSet. + + Possible errors: + + - Returns NOT_FOUND If the Product is not found under the + ProductSet. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest, dict]): + The request object. Request message for the + `RemoveProductFromProductSet` method. + name (str): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (str): + Required. The resource name for the Product to be + removed from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 product_search_service.RemoveProductFromProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.RemoveProductFromProductSetRequest): + request = product_search_service.RemoveProductFromProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.remove_product_from_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_products_in_product_set(self, + request: Union[product_search_service.ListProductsInProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsInProductSetPager: + r"""Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest, dict]): + The request object. Request message for the + `ListProductsInProductSet` method. + name (str): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetPager: + Response message for the ListProductsInProductSet + method. + + 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([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 product_search_service.ListProductsInProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductsInProductSetRequest): + request = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set] + + # 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListProductsInProductSetPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def import_product_sets(self, + request: Union[product_search_service.ImportProductSetsRequest, dict] = None, + *, + parent: str = None, + input_config: product_search_service.ImportProductSetsInputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Args: + request (Union[google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest, dict]): + The request object. Request message for the + `ImportProductSets` method. + parent (str): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_config (google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig): + Required. The input content for the + list of requests. + + This corresponds to the ``input_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.vision_v1p3beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + """ + # 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, input_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 product_search_service.ImportProductSetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ImportProductSetsRequest): + request = product_search_service.ImportProductSetsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if input_config is not None: + request.input_config = input_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.import_product_sets] + + # 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, + product_search_service.ImportProductSetsResponse, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ProductSearchClient", +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py new file mode 100644 index 00000000..1aa2e782 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py @@ -0,0 +1,506 @@ +# -*- 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, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator + +from google.cloud.vision_v1p3beta1.types import product_search_service + + +class ListProductSetsPager: + """A pager for iterating through ``list_product_sets`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``product_sets`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProductSets`` requests and continue to iterate + through the ``product_sets`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` + 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[..., product_search_service.ListProductSetsResponse], + request: product_search_service.ListProductSetsRequest, + response: product_search_service.ListProductSetsResponse, + *, + 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.vision_v1p3beta1.types.ListProductSetsRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListProductSetsResponse): + 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 = product_search_service.ListProductSetsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductSetsResponse]: + 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) -> Iterator[product_search_service.ProductSet]: + for page in self.pages: + yield from page.product_sets + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductSetsAsyncPager: + """A pager for iterating through ``list_product_sets`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``product_sets`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProductSets`` requests and continue to iterate + through the ``product_sets`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` + 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[product_search_service.ListProductSetsResponse]], + request: product_search_service.ListProductSetsRequest, + response: product_search_service.ListProductSetsResponse, + *, + 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.vision_v1p3beta1.types.ListProductSetsRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListProductSetsResponse): + 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 = product_search_service.ListProductSetsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductSetsResponse]: + 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) -> AsyncIterator[product_search_service.ProductSet]: + async def async_generator(): + async for page in self.pages: + for response in page.product_sets: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` + 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[..., product_search_service.ListProductsResponse], + request: product_search_service.ListProductsRequest, + response: product_search_service.ListProductsResponse, + *, + 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.vision_v1p3beta1.types.ListProductsRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListProductsResponse): + 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 = product_search_service.ListProductsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductsResponse]: + 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) -> Iterator[product_search_service.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsAsyncPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` + 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[product_search_service.ListProductsResponse]], + request: product_search_service.ListProductsRequest, + response: product_search_service.ListProductsResponse, + *, + 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.vision_v1p3beta1.types.ListProductsRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListProductsResponse): + 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 = product_search_service.ListProductsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductsResponse]: + 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) -> AsyncIterator[product_search_service.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListReferenceImagesPager: + """A pager for iterating through ``list_reference_images`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``reference_images`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListReferenceImages`` requests and continue to iterate + through the ``reference_images`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` + 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[..., product_search_service.ListReferenceImagesResponse], + request: product_search_service.ListReferenceImagesRequest, + response: product_search_service.ListReferenceImagesResponse, + *, + 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.vision_v1p3beta1.types.ListReferenceImagesRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse): + 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 = product_search_service.ListReferenceImagesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListReferenceImagesResponse]: + 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) -> Iterator[product_search_service.ReferenceImage]: + for page in self.pages: + yield from page.reference_images + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListReferenceImagesAsyncPager: + """A pager for iterating through ``list_reference_images`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``reference_images`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListReferenceImages`` requests and continue to iterate + through the ``reference_images`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` + 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[product_search_service.ListReferenceImagesResponse]], + request: product_search_service.ListReferenceImagesRequest, + response: product_search_service.ListReferenceImagesResponse, + *, + 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.vision_v1p3beta1.types.ListReferenceImagesRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse): + 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 = product_search_service.ListReferenceImagesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListReferenceImagesResponse]: + 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) -> AsyncIterator[product_search_service.ReferenceImage]: + async def async_generator(): + async for page in self.pages: + for response in page.reference_images: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsInProductSetPager: + """A pager for iterating through ``list_products_in_product_set`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProductsInProductSet`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` + 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[..., product_search_service.ListProductsInProductSetResponse], + request: product_search_service.ListProductsInProductSetRequest, + response: product_search_service.ListProductsInProductSetResponse, + *, + 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.vision_v1p3beta1.types.ListProductsInProductSetRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse): + 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 = product_search_service.ListProductsInProductSetRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductsInProductSetResponse]: + 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) -> Iterator[product_search_service.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsInProductSetAsyncPager: + """A pager for iterating through ``list_products_in_product_set`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProductsInProductSet`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` + 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[product_search_service.ListProductsInProductSetResponse]], + request: product_search_service.ListProductsInProductSetRequest, + response: product_search_service.ListProductsInProductSetResponse, + *, + 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.vision_v1p3beta1.types.ListProductsInProductSetRequest): + The initial request object. + response (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse): + 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 = product_search_service.ListProductsInProductSetRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductsInProductSetResponse]: + 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) -> AsyncIterator[product_search_service.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + 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/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py new file mode 100644 index 00000000..22b20282 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/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 ProductSearchTransport +from .grpc import ProductSearchGrpcTransport +from .grpc_asyncio import ProductSearchGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductSearchTransport]] +_transport_registry['grpc'] = ProductSearchGrpcTransport +_transport_registry['grpc_asyncio'] = ProductSearchGrpcAsyncIOTransport + +__all__ = ( + 'ProductSearchTransport', + 'ProductSearchGrpcTransport', + 'ProductSearchGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py new file mode 100644 index 00000000..7caa2763 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py @@ -0,0 +1,534 @@ +# -*- 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.vision_v1p3beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-vision', + ).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 ProductSearchTransport(abc.ABC): + """Abstract transport class for ProductSearch.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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.create_product_set: gapic_v1.method.wrap_method( + self.create_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_product_sets: gapic_v1.method.wrap_method( + self.list_product_sets, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_product_set: gapic_v1.method.wrap_method( + self.get_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.update_product_set: gapic_v1.method.wrap_method( + self.update_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_product_set: gapic_v1.method.wrap_method( + self.delete_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.create_product: gapic_v1.method.wrap_method( + self.create_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_products: gapic_v1.method.wrap_method( + self.list_products, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_product: gapic_v1.method.wrap_method( + self.get_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.update_product: gapic_v1.method.wrap_method( + self.update_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_product: gapic_v1.method.wrap_method( + self.delete_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.create_reference_image: gapic_v1.method.wrap_method( + self.create_reference_image, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_reference_image: gapic_v1.method.wrap_method( + self.delete_reference_image, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_reference_images: gapic_v1.method.wrap_method( + self.list_reference_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_reference_image: gapic_v1.method.wrap_method( + self.get_reference_image, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.add_product_to_product_set: gapic_v1.method.wrap_method( + self.add_product_to_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.remove_product_from_product_set: gapic_v1.method.wrap_method( + self.remove_product_from_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_products_in_product_set: gapic_v1.method.wrap_method( + self.list_products_in_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.import_product_sets: gapic_v1.method.wrap_method( + self.import_product_sets, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + Union[ + product_search_service.ListProductSetsResponse, + Awaitable[product_search_service.ListProductSetsResponse] + ]]: + raise NotImplementedError() + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + Union[ + product_search_service.ListProductsResponse, + Awaitable[product_search_service.ListProductsResponse] + ]]: + raise NotImplementedError() + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + Union[ + product_search_service.ReferenceImage, + Awaitable[product_search_service.ReferenceImage] + ]]: + raise NotImplementedError() + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + Union[ + product_search_service.ListReferenceImagesResponse, + Awaitable[product_search_service.ListReferenceImagesResponse] + ]]: + raise NotImplementedError() + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + Union[ + product_search_service.ReferenceImage, + Awaitable[product_search_service.ReferenceImage] + ]]: + raise NotImplementedError() + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + Union[ + product_search_service.ListProductsInProductSetResponse, + Awaitable[product_search_service.ListProductsInProductSetResponse] + ]]: + raise NotImplementedError() + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ProductSearchTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py new file mode 100644 index 00000000..4daa61a6 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py @@ -0,0 +1,880 @@ +# -*- 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.vision_v1p3beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO + + +class ProductSearchGrpcTransport(ProductSearchTransport): + """gRPC backend transport for ProductSearch. + + Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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 create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the create product set method over gRPC. + + Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Returns: + Callable[[~.CreateProductSetRequest], + ~.ProductSet]: + 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_product_set' not in self._stubs: + self._stubs['create_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProductSet', + request_serializer=product_search_service.CreateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['create_product_set'] + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + product_search_service.ListProductSetsResponse]: + r"""Return a callable for the list product sets method over gRPC. + + Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Returns: + Callable[[~.ListProductSetsRequest], + ~.ListProductSetsResponse]: + 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_product_sets' not in self._stubs: + self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductSets', + request_serializer=product_search_service.ListProductSetsRequest.serialize, + response_deserializer=product_search_service.ListProductSetsResponse.deserialize, + ) + return self._stubs['list_product_sets'] + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the get product set method over gRPC. + + Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.GetProductSetRequest], + ~.ProductSet]: + 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 'get_product_set' not in self._stubs: + self._stubs['get_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/GetProductSet', + request_serializer=product_search_service.GetProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['get_product_set'] + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the update product set method over gRPC. + + Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Returns: + Callable[[~.UpdateProductSetRequest], + ~.ProductSet]: + 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 'update_product_set' not in self._stubs: + self._stubs['update_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProductSet', + request_serializer=product_search_service.UpdateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['update_product_set'] + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product set method over gRPC. + + Permanently deletes a ProductSet. All Products and + ReferenceImages in the ProductSet will be deleted. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.DeleteProductSetRequest], + ~.Empty]: + 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_product_set' not in self._stubs: + self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProductSet', + request_serializer=product_search_service.DeleteProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_set'] + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + product_search_service.Product]: + r"""Return a callable for the create product method over gRPC. + + Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Returns: + Callable[[~.CreateProductRequest], + ~.Product]: + 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_product' not in self._stubs: + self._stubs['create_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProduct', + request_serializer=product_search_service.CreateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['create_product'] + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + product_search_service.ListProductsResponse]: + r"""Return a callable for the list products method over gRPC. + + Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsRequest], + ~.ListProductsResponse]: + 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_products' not in self._stubs: + self._stubs['list_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListProducts', + request_serializer=product_search_service.ListProductsRequest.serialize, + response_deserializer=product_search_service.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + product_search_service.Product]: + r"""Return a callable for the get product method over gRPC. + + Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Returns: + Callable[[~.GetProductRequest], + ~.Product]: + 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 'get_product' not in self._stubs: + self._stubs['get_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/GetProduct', + request_serializer=product_search_service.GetProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + product_search_service.Product]: + r"""Return a callable for the update product method over gRPC. + + Makes changes to a Product resource. Only display_name, + description and labels can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Returns: + Callable[[~.UpdateProductRequest], + ~.Product]: + 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 'update_product' not in self._stubs: + self._stubs['update_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProduct', + request_serializer=product_search_service.UpdateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['update_product'] + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product method over gRPC. + + Permanently deletes a product and its reference images. + + Metadata of the product and all its images will be deleted right + away, but search queries against ProductSets containing the + product may still work until all related caches are refreshed. + + Possible errors: + + - Returns NOT_FOUND if the product does not exist. + + Returns: + Callable[[~.DeleteProductRequest], + ~.Empty]: + 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_product' not in self._stubs: + self._stubs['delete_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProduct', + request_serializer=product_search_service.DeleteProductRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product'] + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + product_search_service.ReferenceImage]: + r"""Return a callable for the create reference image method over gRPC. + + Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Returns: + Callable[[~.CreateReferenceImageRequest], + ~.ReferenceImage]: + 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_reference_image' not in self._stubs: + self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/CreateReferenceImage', + request_serializer=product_search_service.CreateReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['create_reference_image'] + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete reference image method over gRPC. + + Permanently deletes a reference image. + + The image metadata will be deleted right away, but search + queries against ProductSets containing the image may still work + until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the reference image does not exist. + + Returns: + Callable[[~.DeleteReferenceImageRequest], + ~.Empty]: + 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_reference_image' not in self._stubs: + self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteReferenceImage', + request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_reference_image'] + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + product_search_service.ListReferenceImagesResponse]: + r"""Return a callable for the list reference images method over gRPC. + + Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Returns: + Callable[[~.ListReferenceImagesRequest], + ~.ListReferenceImagesResponse]: + 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_reference_images' not in self._stubs: + self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListReferenceImages', + request_serializer=product_search_service.ListReferenceImagesRequest.serialize, + response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, + ) + return self._stubs['list_reference_images'] + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + product_search_service.ReferenceImage]: + r"""Return a callable for the get reference image method over gRPC. + + Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Returns: + Callable[[~.GetReferenceImageRequest], + ~.ReferenceImage]: + 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 'get_reference_image' not in self._stubs: + self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/GetReferenceImage', + request_serializer=product_search_service.GetReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['get_reference_image'] + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the add product to product set method over gRPC. + + Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Returns: + Callable[[~.AddProductToProductSetRequest], + ~.Empty]: + 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 'add_product_to_product_set' not in self._stubs: + self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet', + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['add_product_to_product_set'] + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the remove product from product + set method over gRPC. + + Removes a Product from the specified ProductSet. + + Possible errors: + + - Returns NOT_FOUND If the Product is not found under the + ProductSet. + + Returns: + Callable[[~.RemoveProductFromProductSetRequest], + ~.Empty]: + 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 'remove_product_from_product_set' not in self._stubs: + self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet', + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['remove_product_from_product_set'] + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + product_search_service.ListProductsInProductSetResponse]: + r"""Return a callable for the list products in product set method over gRPC. + + Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsInProductSetRequest], + ~.ListProductsInProductSetResponse]: + 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_products_in_product_set' not in self._stubs: + self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet', + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) + return self._stubs['list_products_in_product_set'] + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + operations_pb2.Operation]: + r"""Return a callable for the import product sets method over gRPC. + + Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Returns: + Callable[[~.ImportProductSetsRequest], + ~.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 'import_product_sets' not in self._stubs: + self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ImportProductSets', + request_serializer=product_search_service.ImportProductSetsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['import_product_sets'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ProductSearchGrpcTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py new file mode 100644 index 00000000..1516a119 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py @@ -0,0 +1,885 @@ +# -*- 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.vision_v1p3beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductSearchGrpcTransport + + +class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): + """gRPC AsyncIO backend transport for ProductSearch. + + Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p3beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p3beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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 create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the create product set method over gRPC. + + Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Returns: + Callable[[~.CreateProductSetRequest], + Awaitable[~.ProductSet]]: + 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_product_set' not in self._stubs: + self._stubs['create_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProductSet', + request_serializer=product_search_service.CreateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['create_product_set'] + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + Awaitable[product_search_service.ListProductSetsResponse]]: + r"""Return a callable for the list product sets method over gRPC. + + Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Returns: + Callable[[~.ListProductSetsRequest], + Awaitable[~.ListProductSetsResponse]]: + 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_product_sets' not in self._stubs: + self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductSets', + request_serializer=product_search_service.ListProductSetsRequest.serialize, + response_deserializer=product_search_service.ListProductSetsResponse.deserialize, + ) + return self._stubs['list_product_sets'] + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the get product set method over gRPC. + + Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.GetProductSetRequest], + Awaitable[~.ProductSet]]: + 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 'get_product_set' not in self._stubs: + self._stubs['get_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/GetProductSet', + request_serializer=product_search_service.GetProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['get_product_set'] + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the update product set method over gRPC. + + Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Returns: + Callable[[~.UpdateProductSetRequest], + Awaitable[~.ProductSet]]: + 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 'update_product_set' not in self._stubs: + self._stubs['update_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProductSet', + request_serializer=product_search_service.UpdateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['update_product_set'] + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product set method over gRPC. + + Permanently deletes a ProductSet. All Products and + ReferenceImages in the ProductSet will be deleted. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.DeleteProductSetRequest], + Awaitable[~.Empty]]: + 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_product_set' not in self._stubs: + self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProductSet', + request_serializer=product_search_service.DeleteProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_set'] + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the create product method over gRPC. + + Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Returns: + Callable[[~.CreateProductRequest], + Awaitable[~.Product]]: + 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_product' not in self._stubs: + self._stubs['create_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProduct', + request_serializer=product_search_service.CreateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['create_product'] + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + Awaitable[product_search_service.ListProductsResponse]]: + r"""Return a callable for the list products method over gRPC. + + Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsRequest], + Awaitable[~.ListProductsResponse]]: + 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_products' not in self._stubs: + self._stubs['list_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListProducts', + request_serializer=product_search_service.ListProductsRequest.serialize, + response_deserializer=product_search_service.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the get product method over gRPC. + + Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Returns: + Callable[[~.GetProductRequest], + Awaitable[~.Product]]: + 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 'get_product' not in self._stubs: + self._stubs['get_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/GetProduct', + request_serializer=product_search_service.GetProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the update product method over gRPC. + + Makes changes to a Product resource. Only display_name, + description and labels can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Returns: + Callable[[~.UpdateProductRequest], + Awaitable[~.Product]]: + 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 'update_product' not in self._stubs: + self._stubs['update_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProduct', + request_serializer=product_search_service.UpdateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['update_product'] + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product method over gRPC. + + Permanently deletes a product and its reference images. + + Metadata of the product and all its images will be deleted right + away, but search queries against ProductSets containing the + product may still work until all related caches are refreshed. + + Possible errors: + + - Returns NOT_FOUND if the product does not exist. + + Returns: + Callable[[~.DeleteProductRequest], + Awaitable[~.Empty]]: + 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_product' not in self._stubs: + self._stubs['delete_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProduct', + request_serializer=product_search_service.DeleteProductRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product'] + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + Awaitable[product_search_service.ReferenceImage]]: + r"""Return a callable for the create reference image method over gRPC. + + Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Returns: + Callable[[~.CreateReferenceImageRequest], + Awaitable[~.ReferenceImage]]: + 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_reference_image' not in self._stubs: + self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/CreateReferenceImage', + request_serializer=product_search_service.CreateReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['create_reference_image'] + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete reference image method over gRPC. + + Permanently deletes a reference image. + + The image metadata will be deleted right away, but search + queries against ProductSets containing the image may still work + until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Possible errors: + + - Returns NOT_FOUND if the reference image does not exist. + + Returns: + Callable[[~.DeleteReferenceImageRequest], + Awaitable[~.Empty]]: + 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_reference_image' not in self._stubs: + self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteReferenceImage', + request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_reference_image'] + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + Awaitable[product_search_service.ListReferenceImagesResponse]]: + r"""Return a callable for the list reference images method over gRPC. + + Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Returns: + Callable[[~.ListReferenceImagesRequest], + Awaitable[~.ListReferenceImagesResponse]]: + 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_reference_images' not in self._stubs: + self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListReferenceImages', + request_serializer=product_search_service.ListReferenceImagesRequest.serialize, + response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, + ) + return self._stubs['list_reference_images'] + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + Awaitable[product_search_service.ReferenceImage]]: + r"""Return a callable for the get reference image method over gRPC. + + Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Returns: + Callable[[~.GetReferenceImageRequest], + Awaitable[~.ReferenceImage]]: + 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 'get_reference_image' not in self._stubs: + self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/GetReferenceImage', + request_serializer=product_search_service.GetReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['get_reference_image'] + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the add product to product set method over gRPC. + + Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Returns: + Callable[[~.AddProductToProductSetRequest], + Awaitable[~.Empty]]: + 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 'add_product_to_product_set' not in self._stubs: + self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet', + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['add_product_to_product_set'] + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the remove product from product + set method over gRPC. + + Removes a Product from the specified ProductSet. + + Possible errors: + + - Returns NOT_FOUND If the Product is not found under the + ProductSet. + + Returns: + Callable[[~.RemoveProductFromProductSetRequest], + Awaitable[~.Empty]]: + 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 'remove_product_from_product_set' not in self._stubs: + self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet', + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['remove_product_from_product_set'] + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + Awaitable[product_search_service.ListProductsInProductSetResponse]]: + r"""Return a callable for the list products in product set method over gRPC. + + Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsInProductSetRequest], + Awaitable[~.ListProductsInProductSetResponse]]: + 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_products_in_product_set' not in self._stubs: + self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet', + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) + return self._stubs['list_products_in_product_set'] + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the import product sets method over gRPC. + + Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Returns: + Callable[[~.ImportProductSetsRequest], + 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 'import_product_sets' not in self._stubs: + self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p3beta1.ProductSearch/ImportProductSets', + request_serializer=product_search_service.ImportProductSetsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['import_product_sets'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ProductSearchGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py new file mode 100644 index 00000000..651a3e18 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py @@ -0,0 +1,190 @@ +# -*- 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 .geometry import ( + BoundingPoly, + NormalizedBoundingPoly, + NormalizedVertex, + Position, + Vertex, +) +from .image_annotator import ( + AnnotateFileResponse, + AnnotateImageRequest, + AnnotateImageResponse, + AsyncAnnotateFileRequest, + AsyncAnnotateFileResponse, + AsyncBatchAnnotateFilesRequest, + AsyncBatchAnnotateFilesResponse, + BatchAnnotateImagesRequest, + BatchAnnotateImagesResponse, + ColorInfo, + CropHint, + CropHintsAnnotation, + CropHintsParams, + DominantColorsAnnotation, + EntityAnnotation, + FaceAnnotation, + Feature, + GcsDestination, + GcsSource, + Image, + ImageAnnotationContext, + ImageContext, + ImageProperties, + ImageSource, + InputConfig, + LatLongRect, + LocalizedObjectAnnotation, + LocationInfo, + OperationMetadata, + OutputConfig, + Property, + SafeSearchAnnotation, + TextDetectionParams, + WebDetectionParams, + Likelihood, +) +from .product_search import ( + ProductSearchParams, + ProductSearchResults, + ProductSearchCategory, + ProductSearchResultsView, +) +from .product_search_service import ( + AddProductToProductSetRequest, + BatchOperationMetadata, + CreateProductRequest, + CreateProductSetRequest, + CreateReferenceImageRequest, + DeleteProductRequest, + DeleteProductSetRequest, + DeleteReferenceImageRequest, + GetProductRequest, + GetProductSetRequest, + GetReferenceImageRequest, + ImportProductSetsGcsSource, + ImportProductSetsInputConfig, + ImportProductSetsRequest, + ImportProductSetsResponse, + ListProductSetsRequest, + ListProductSetsResponse, + ListProductsInProductSetRequest, + ListProductsInProductSetResponse, + ListProductsRequest, + ListProductsResponse, + ListReferenceImagesRequest, + ListReferenceImagesResponse, + Product, + ProductSet, + ReferenceImage, + RemoveProductFromProductSetRequest, + UpdateProductRequest, + UpdateProductSetRequest, +) +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) + +__all__ = ( + 'BoundingPoly', + 'NormalizedBoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocalizedObjectAnnotation', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'ProductSearchParams', + 'ProductSearchResults', + 'ProductSearchCategory', + 'ProductSearchResultsView', + 'AddProductToProductSetRequest', + 'BatchOperationMetadata', + 'CreateProductRequest', + 'CreateProductSetRequest', + 'CreateReferenceImageRequest', + 'DeleteProductRequest', + 'DeleteProductSetRequest', + 'DeleteReferenceImageRequest', + 'GetProductRequest', + 'GetProductSetRequest', + 'GetReferenceImageRequest', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ListProductsRequest', + 'ListProductsResponse', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'Product', + 'ProductSet', + 'ReferenceImage', + 'RemoveProductFromProductSetRequest', + 'UpdateProductRequest', + 'UpdateProductSetRequest', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.py new file mode 100644 index 00000000..1b4a7225 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p3beta1', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + 'NormalizedBoundingPoly', + 'Position', + }, +) + + +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.vision_v1p3beta1.types.Vertex]): + The bounding polygon vertices. + normalized_vertices (Sequence[google.cloud.vision_v1p3beta1.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', + ) + + +class NormalizedBoundingPoly(proto.Message): + r"""A normalized bounding polygon around a portion of an image. + + Attributes: + vertices (Sequence[google.cloud.vision_v1p3beta1.types.NormalizedVertex]): + Normalized vertices of the bounding polygon. + """ + + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='NormalizedVertex', + ) + + +class Position(proto.Message): + r"""A 3D position in the image, used primarily for Face detection + landmarks. A valid Position must have both x and y coordinates. + The position coordinates are in the same scale as the original + image. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate. + z (float): + Z coordinate (or depth). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + z = proto.Field( + proto.FLOAT, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py new file mode 100644 index 00000000..45d94d86 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py @@ -0,0 +1,1327 @@ +# -*- 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.vision_v1p3beta1.types import geometry +from google.cloud.vision_v1p3beta1.types import product_search +from google.cloud.vision_v1p3beta1.types import text_annotation +from google.cloud.vision_v1p3beta1.types import web_detection as gcv_web_detection +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 latlng_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p3beta1', + manifest={ + 'Likelihood', + 'Feature', + 'ImageSource', + 'Image', + 'FaceAnnotation', + 'LocationInfo', + 'Property', + 'EntityAnnotation', + 'LocalizedObjectAnnotation', + 'SafeSearchAnnotation', + 'LatLongRect', + 'ColorInfo', + 'DominantColorsAnnotation', + 'ImageProperties', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'WebDetectionParams', + 'TextDetectionParams', + 'ImageContext', + 'AnnotateImageRequest', + 'ImageAnnotationContext', + 'AnnotateImageResponse', + 'AnnotateFileResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'InputConfig', + 'OutputConfig', + 'GcsSource', + 'GcsDestination', + 'OperationMetadata', + }, +) + + +class Likelihood(proto.Enum): + r"""A bucketized representation of likelihood, which is intended + to give clients highly stable results across model upgrades. + """ + UNKNOWN = 0 + VERY_UNLIKELY = 1 + UNLIKELY = 2 + POSSIBLE = 3 + LIKELY = 4 + VERY_LIKELY = 5 + + +class Feature(proto.Message): + r"""The type of Google Cloud Vision API detection to perform, and the + maximum number of results to return for that type. Multiple + ``Feature`` objects can be specified in the ``features`` list. + + Attributes: + type_ (google.cloud.vision_v1p3beta1.types.Feature.Type): + The feature type. + max_results (int): + Maximum number of results of this type. Does not apply to + ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or + ``CROP_HINTS``. + model (str): + Model to use for the feature. + Supported values: "builtin/stable" (the default + if unset) and "builtin/latest". + """ + class Type(proto.Enum): + r"""Type of Google Cloud Vision API feature to be extracted.""" + TYPE_UNSPECIFIED = 0 + FACE_DETECTION = 1 + LANDMARK_DETECTION = 2 + LOGO_DETECTION = 3 + LABEL_DETECTION = 4 + TEXT_DETECTION = 5 + DOCUMENT_TEXT_DETECTION = 11 + SAFE_SEARCH_DETECTION = 6 + IMAGE_PROPERTIES = 7 + CROP_HINTS = 9 + WEB_DETECTION = 10 + PRODUCT_SEARCH = 12 + OBJECT_LOCALIZATION = 19 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum=Type, + ) + max_results = proto.Field( + proto.INT32, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + + +class ImageSource(proto.Message): + r"""External image source (Google Cloud Storage or web URL image + location). + + Attributes: + gcs_image_uri (str): + **Use ``image_uri`` instead.** + + The 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. + image_uri (str): + The URI of the source image. Can be either: + + 1. A 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. + + 2. A publicly-accessible image HTTP/HTTPS URL. When fetching + images from HTTP/HTTPS URLs, Google cannot guarantee that + the request will be completed. Your request may fail if + the specified host denies the request (e.g. due to + request throttling or DOS prevention), or if Google + throttles requests to the site for abuse prevention. You + should not depend on externally-hosted images for + production applications. + + When both ``gcs_image_uri`` and ``image_uri`` are specified, + ``image_uri`` takes precedence. + """ + + gcs_image_uri = proto.Field( + proto.STRING, + number=1, + ) + image_uri = proto.Field( + proto.STRING, + number=2, + ) + + +class Image(proto.Message): + r"""Client image to perform Google Cloud Vision API tasks over. + + Attributes: + content (bytes): + Image content, represented as a stream of bytes. Note: As + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + source (google.cloud.vision_v1p3beta1.types.ImageSource): + Google Cloud Storage image location, or publicly-accessible + image URL. If both ``content`` and ``source`` are provided + for an image, ``content`` takes precedence and is used to + perform the image annotation request. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + source = proto.Field( + proto.MESSAGE, + number=2, + message='ImageSource', + ) + + +class FaceAnnotation(proto.Message): + r"""A face annotation object contains the results of face + detection. + + Attributes: + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding polygon around the face. The coordinates of the + bounding box are in the original image's scale, as returned + in ``ImageParams``. The bounding box is computed to "frame" + the face in accordance with human expectations. It is based + on the landmarker results. Note that one or more x and/or y + coordinates may not be generated in the ``BoundingPoly`` + (the polygon will be unbounded) if only a partial face + appears in the image to be annotated. + fd_bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The ``fd_bounding_poly`` bounding polygon is tighter than + the ``boundingPoly``, and encloses only the skin part of the + face. Typically, it is used to eliminate the face from any + image analysis that detects the "amount of skin" visible in + an image. It is not based on the landmarker results, only on + the initial face detection, hence the fd (face detection) + prefix. + landmarks (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark]): + Detected face landmarks. + roll_angle (float): + Roll angle, which indicates the amount of + clockwise/anti-clockwise rotation of the face relative to + the image vertical about the axis perpendicular to the face. + Range [-180,180]. + pan_angle (float): + Yaw angle, which indicates the leftward/rightward angle that + the face is pointing relative to the vertical plane + perpendicular to the image. Range [-180,180]. + tilt_angle (float): + Pitch angle, which indicates the upwards/downwards angle + that the face is pointing relative to the image's horizontal + plane. Range [-180,180]. + detection_confidence (float): + Detection confidence. Range [0, 1]. + landmarking_confidence (float): + Face landmarking confidence. Range [0, 1]. + joy_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Joy likelihood. + sorrow_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Sorrow likelihood. + anger_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Anger likelihood. + surprise_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Surprise likelihood. + under_exposed_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Under-exposed likelihood. + blurred_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Blurred likelihood. + headwear_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): + Headwear likelihood. + """ + + class Landmark(proto.Message): + r"""A face-specific landmark (for example, a face feature). + + Attributes: + type_ (google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark.Type): + Face landmark type. + position (google.cloud.vision_v1p3beta1.types.Position): + Face landmark position. + """ + class Type(proto.Enum): + r"""Face landmark (feature) type. Left and right are defined from the + vantage of the viewer of the image without considering mirror + projections typical of photos. So, ``LEFT_EYE``, typically, is the + person's right eye. + """ + UNKNOWN_LANDMARK = 0 + LEFT_EYE = 1 + RIGHT_EYE = 2 + LEFT_OF_LEFT_EYEBROW = 3 + RIGHT_OF_LEFT_EYEBROW = 4 + LEFT_OF_RIGHT_EYEBROW = 5 + RIGHT_OF_RIGHT_EYEBROW = 6 + MIDPOINT_BETWEEN_EYES = 7 + NOSE_TIP = 8 + UPPER_LIP = 9 + LOWER_LIP = 10 + MOUTH_LEFT = 11 + MOUTH_RIGHT = 12 + MOUTH_CENTER = 13 + NOSE_BOTTOM_RIGHT = 14 + NOSE_BOTTOM_LEFT = 15 + NOSE_BOTTOM_CENTER = 16 + LEFT_EYE_TOP_BOUNDARY = 17 + LEFT_EYE_RIGHT_CORNER = 18 + LEFT_EYE_BOTTOM_BOUNDARY = 19 + LEFT_EYE_LEFT_CORNER = 20 + RIGHT_EYE_TOP_BOUNDARY = 21 + RIGHT_EYE_RIGHT_CORNER = 22 + RIGHT_EYE_BOTTOM_BOUNDARY = 23 + RIGHT_EYE_LEFT_CORNER = 24 + LEFT_EYEBROW_UPPER_MIDPOINT = 25 + RIGHT_EYEBROW_UPPER_MIDPOINT = 26 + LEFT_EAR_TRAGION = 27 + RIGHT_EAR_TRAGION = 28 + LEFT_EYE_PUPIL = 29 + RIGHT_EYE_PUPIL = 30 + FOREHEAD_GLABELLA = 31 + CHIN_GNATHION = 32 + CHIN_LEFT_GONION = 33 + CHIN_RIGHT_GONION = 34 + + type_ = proto.Field( + proto.ENUM, + number=3, + enum='FaceAnnotation.Landmark.Type', + ) + position = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.Position, + ) + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + fd_bounding_poly = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + landmarks = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Landmark, + ) + roll_angle = proto.Field( + proto.FLOAT, + number=4, + ) + pan_angle = proto.Field( + proto.FLOAT, + number=5, + ) + tilt_angle = proto.Field( + proto.FLOAT, + number=6, + ) + detection_confidence = proto.Field( + proto.FLOAT, + number=7, + ) + landmarking_confidence = proto.Field( + proto.FLOAT, + number=8, + ) + joy_likelihood = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + sorrow_likelihood = proto.Field( + proto.ENUM, + number=10, + enum='Likelihood', + ) + anger_likelihood = proto.Field( + proto.ENUM, + number=11, + enum='Likelihood', + ) + surprise_likelihood = proto.Field( + proto.ENUM, + number=12, + enum='Likelihood', + ) + under_exposed_likelihood = proto.Field( + proto.ENUM, + number=13, + enum='Likelihood', + ) + blurred_likelihood = proto.Field( + proto.ENUM, + number=14, + enum='Likelihood', + ) + headwear_likelihood = proto.Field( + proto.ENUM, + number=15, + enum='Likelihood', + ) + + +class LocationInfo(proto.Message): + r"""Detected entity location information. + + Attributes: + lat_lng (google.type.latlng_pb2.LatLng): + lat/long location coordinates. + """ + + lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + + +class Property(proto.Message): + r"""A ``Property`` consists of a user-supplied name/value pair. + + Attributes: + name (str): + Name of the property. + value (str): + Value of the property. + uint64_value (int): + Value of numeric properties. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + uint64_value = proto.Field( + proto.UINT64, + number=3, + ) + + +class EntityAnnotation(proto.Message): + r"""Set of detected entity features. + + Attributes: + mid (str): + Opaque entity ID. Some IDs may be available in `Google + Knowledge Graph Search + API `__. + locale (str): + The language code for the locale in which the entity textual + ``description`` is expressed. + description (str): + Entity textual description, expressed in its ``locale`` + language. + score (float): + Overall score of the result. Range [0, 1]. + confidence (float): + **Deprecated. Use ``score`` instead.** The accuracy of the + entity detection in an image. For example, for an image in + which the "Eiffel Tower" entity is detected, this field + represents the confidence that there is a tower in the query + image. Range [0, 1]. + topicality (float): + The relevancy of the ICA (Image Content Annotation) label to + the image. For example, the relevancy of "tower" is likely + higher to an image containing the detected "Eiffel Tower" + than to an image containing a detected distant towering + building, even though the confidence that there is a tower + in each image may be the same. Range [0, 1]. + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): + Image region to which this entity belongs. Not produced for + ``LABEL_DETECTION`` features. + locations (Sequence[google.cloud.vision_v1p3beta1.types.LocationInfo]): + The location information for the detected entity. Multiple + ``LocationInfo`` elements can be present because one + location may indicate the location of the scene in the + image, and another location may indicate the location of the + place where the image was taken. Location information is + usually present for landmarks. + properties (Sequence[google.cloud.vision_v1p3beta1.types.Property]): + Some entities may have optional user-supplied ``Property`` + (name/value) fields, such a score or string that qualifies + the entity. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + locale = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + topicality = proto.Field( + proto.FLOAT, + number=6, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=7, + message=geometry.BoundingPoly, + ) + locations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='LocationInfo', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Property', + ) + + +class LocalizedObjectAnnotation(proto.Message): + r"""Set of detected objects with bounding boxes. + + Attributes: + mid (str): + Object ID that should align with + EntityAnnotation mid. + 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. + name (str): + Object name, expressed in its ``language_code`` language. + score (float): + Score of the result. Range [0, 1]. + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): + Image region to which this object belongs. + This must be populated. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + name = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=5, + message=geometry.BoundingPoly, + ) + + +class SafeSearchAnnotation(proto.Message): + r"""Set of features pertaining to the image, computed by computer + vision methods over safe-search verticals (for example, adult, + spoof, medical, violence). + + Attributes: + adult (google.cloud.vision_v1p3beta1.types.Likelihood): + Represents the adult content likelihood for + the image. Adult content may contain elements + such as nudity, pornographic images or cartoons, + or sexual activities. + spoof (google.cloud.vision_v1p3beta1.types.Likelihood): + Spoof likelihood. The likelihood that an + modification was made to the image's canonical + version to make it appear funny or offensive. + medical (google.cloud.vision_v1p3beta1.types.Likelihood): + Likelihood that this is a medical image. + violence (google.cloud.vision_v1p3beta1.types.Likelihood): + Likelihood that this image contains violent + content. + racy (google.cloud.vision_v1p3beta1.types.Likelihood): + Likelihood that the request image contains + racy content. Racy content may include (but is + not limited to) skimpy or sheer clothing, + strategically covered nudity, lewd or + provocative poses, or close-ups of sensitive + body areas. + """ + + adult = proto.Field( + proto.ENUM, + number=1, + enum='Likelihood', + ) + spoof = proto.Field( + proto.ENUM, + number=2, + enum='Likelihood', + ) + medical = proto.Field( + proto.ENUM, + number=3, + enum='Likelihood', + ) + violence = proto.Field( + proto.ENUM, + number=4, + enum='Likelihood', + ) + racy = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + + +class LatLongRect(proto.Message): + r"""Rectangle determined by min and max ``LatLng`` pairs. + + Attributes: + min_lat_lng (google.type.latlng_pb2.LatLng): + Min lat/long pair. + max_lat_lng (google.type.latlng_pb2.LatLng): + Max lat/long pair. + """ + + min_lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + max_lat_lng = proto.Field( + proto.MESSAGE, + number=2, + message=latlng_pb2.LatLng, + ) + + +class ColorInfo(proto.Message): + r"""Color information consists of RGB channels, score, and the + fraction of the image that the color occupies in the image. + + Attributes: + color (google.type.color_pb2.Color): + RGB components of the color. + score (float): + Image-specific score for this color. Value in range [0, 1]. + pixel_fraction (float): + The fraction of pixels the color occupies in the image. + Value in range [0, 1]. + """ + + color = proto.Field( + proto.MESSAGE, + number=1, + message=color_pb2.Color, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + pixel_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class DominantColorsAnnotation(proto.Message): + r"""Set of dominant colors and their corresponding scores. + + Attributes: + colors (Sequence[google.cloud.vision_v1p3beta1.types.ColorInfo]): + RGB color values with their score and pixel + fraction. + """ + + colors = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ColorInfo', + ) + + +class ImageProperties(proto.Message): + r"""Stores image properties, such as dominant colors. + + Attributes: + dominant_colors (google.cloud.vision_v1p3beta1.types.DominantColorsAnnotation): + If present, dominant colors completed + successfully. + """ + + dominant_colors = proto.Field( + proto.MESSAGE, + number=1, + message='DominantColorsAnnotation', + ) + + +class CropHint(proto.Message): + r"""Single crop hint that is used to generate a new crop when + serving an image. + + Attributes: + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding polygon for the crop region. The coordinates of + the bounding box are in the original image's scale, as + returned in ``ImageParams``. + confidence (float): + Confidence of this being a salient region. Range [0, 1]. + importance_fraction (float): + Fraction of importance of this salient region + with respect to the original image. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + importance_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class CropHintsAnnotation(proto.Message): + r"""Set of crop hints that are used to generate new crops when + serving images. + + Attributes: + crop_hints (Sequence[google.cloud.vision_v1p3beta1.types.CropHint]): + Crop hint results. + """ + + crop_hints = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='CropHint', + ) + + +class CropHintsParams(proto.Message): + r"""Parameters for crop hints annotation request. + + Attributes: + aspect_ratios (Sequence[float]): + Aspect ratios in floats, representing the + ratio of the width to the height of the image. + For example, if the desired aspect ratio is 4/3, + the corresponding float value should be 1.33333. + If not specified, the best possible crop is + returned. The number of provided aspect ratios + is limited to a maximum of 16; any aspect ratios + provided after the 16th are ignored. + """ + + aspect_ratios = proto.RepeatedField( + proto.FLOAT, + number=1, + ) + + +class WebDetectionParams(proto.Message): + r"""Parameters for web detection request. + + Attributes: + include_geo_results (bool): + Whether to include results derived from the + geo information in the image. + """ + + include_geo_results = proto.Field( + proto.BOOL, + number=2, + ) + + +class TextDetectionParams(proto.Message): + r"""Parameters for text detections. This is used to control + TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. + + Attributes: + enable_text_detection_confidence_score (bool): + By default, Cloud Vision API only includes confidence score + for DOCUMENT_TEXT_DETECTION result. Set the flag to true to + include confidence score for TEXT_DETECTION as well. + """ + + enable_text_detection_confidence_score = proto.Field( + proto.BOOL, + number=9, + ) + + +class ImageContext(proto.Message): + r"""Image context and/or feature-specific parameters. + + Attributes: + lat_long_rect (google.cloud.vision_v1p3beta1.types.LatLongRect): + Not used. + language_hints (Sequence[str]): + List of languages to use for TEXT_DETECTION. 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). + Text detection returns an error if one or more of the + specified languages is not one of the `supported + languages `__. + crop_hints_params (google.cloud.vision_v1p3beta1.types.CropHintsParams): + Parameters for crop hints annotation request. + product_search_params (google.cloud.vision_v1p3beta1.types.ProductSearchParams): + Parameters for product search. + web_detection_params (google.cloud.vision_v1p3beta1.types.WebDetectionParams): + Parameters for web detection. + text_detection_params (google.cloud.vision_v1p3beta1.types.TextDetectionParams): + Parameters for text detection and document + text detection. + """ + + lat_long_rect = proto.Field( + proto.MESSAGE, + number=1, + message='LatLongRect', + ) + language_hints = proto.RepeatedField( + proto.STRING, + number=2, + ) + crop_hints_params = proto.Field( + proto.MESSAGE, + number=4, + message='CropHintsParams', + ) + product_search_params = proto.Field( + proto.MESSAGE, + number=5, + message=product_search.ProductSearchParams, + ) + web_detection_params = proto.Field( + proto.MESSAGE, + number=6, + message='WebDetectionParams', + ) + text_detection_params = proto.Field( + proto.MESSAGE, + number=12, + message='TextDetectionParams', + ) + + +class AnnotateImageRequest(proto.Message): + r"""Request for performing Google Cloud Vision API tasks over a + user-provided image, with user-requested features. + + Attributes: + image (google.cloud.vision_v1p3beta1.types.Image): + The image to be processed. + features (Sequence[google.cloud.vision_v1p3beta1.types.Feature]): + Requested features. + image_context (google.cloud.vision_v1p3beta1.types.ImageContext): + Additional context that may accompany the + image. + """ + + image = proto.Field( + proto.MESSAGE, + number=1, + message='Image', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + + +class ImageAnnotationContext(proto.Message): + r"""If an image was produced from a file (e.g. a PDF), this + message gives information about the source of that image. + + Attributes: + uri (str): + The URI of the file used to produce the + image. + page_number (int): + If the file was a PDF or TIFF, this field + gives the page number within the file used to + produce the image. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + page_number = proto.Field( + proto.INT32, + number=2, + ) + + +class AnnotateImageResponse(proto.Message): + r"""Response to an image annotation request. + + Attributes: + face_annotations (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation]): + If present, face detection has completed + successfully. + landmark_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): + If present, landmark detection has completed + successfully. + logo_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): + If present, logo detection has completed + successfully. + label_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): + If present, label detection has completed + successfully. + localized_object_annotations (Sequence[google.cloud.vision_v1p3beta1.types.LocalizedObjectAnnotation]): + If present, localized object detection has + completed successfully. This will be sorted + descending by confidence score. + text_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): + If present, text (OCR) detection has + completed successfully. + full_text_annotation (google.cloud.vision_v1p3beta1.types.TextAnnotation): + If present, text (OCR) detection or document + (OCR) text detection has completed successfully. + This annotation provides the structural + hierarchy for the OCR detected text. + safe_search_annotation (google.cloud.vision_v1p3beta1.types.SafeSearchAnnotation): + If present, safe-search annotation has + completed successfully. + image_properties_annotation (google.cloud.vision_v1p3beta1.types.ImageProperties): + If present, image properties were extracted + successfully. + crop_hints_annotation (google.cloud.vision_v1p3beta1.types.CropHintsAnnotation): + If present, crop hints have completed + successfully. + web_detection (google.cloud.vision_v1p3beta1.types.WebDetection): + If present, web detection has completed + successfully. + product_search_results (google.cloud.vision_v1p3beta1.types.ProductSearchResults): + If present, product search has completed + successfully. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the operation. Note + that filled-in image annotations are guaranteed to be + correct, even when ``error`` is set. + context (google.cloud.vision_v1p3beta1.types.ImageAnnotationContext): + If present, contextual information is needed + to understand where this image comes from. + """ + + face_annotations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='FaceAnnotation', + ) + landmark_annotations = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='EntityAnnotation', + ) + logo_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='EntityAnnotation', + ) + label_annotations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='EntityAnnotation', + ) + localized_object_annotations = proto.RepeatedField( + proto.MESSAGE, + number=22, + message='LocalizedObjectAnnotation', + ) + text_annotations = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='EntityAnnotation', + ) + full_text_annotation = proto.Field( + proto.MESSAGE, + number=12, + message=text_annotation.TextAnnotation, + ) + safe_search_annotation = proto.Field( + proto.MESSAGE, + number=6, + message='SafeSearchAnnotation', + ) + image_properties_annotation = proto.Field( + proto.MESSAGE, + number=8, + message='ImageProperties', + ) + crop_hints_annotation = proto.Field( + proto.MESSAGE, + number=11, + message='CropHintsAnnotation', + ) + web_detection = proto.Field( + proto.MESSAGE, + number=13, + message=gcv_web_detection.WebDetection, + ) + product_search_results = proto.Field( + proto.MESSAGE, + number=14, + message=product_search.ProductSearchResults, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + context = proto.Field( + proto.MESSAGE, + number=21, + message='ImageAnnotationContext', + ) + + +class AnnotateFileResponse(proto.Message): + r"""Response to a single file annotation request. A file may + contain one or more images, which individually have their own + responses. + + Attributes: + input_config (google.cloud.vision_v1p3beta1.types.InputConfig): + Information about the file for which this + response is generated. + responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): + Individual responses to images found within + the file. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + responses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='AnnotateImageResponse', + ) + + +class BatchAnnotateImagesRequest(proto.Message): + r"""Multiple image annotation requests are batched into a single + service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]): + Individual image annotation requests for this + batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + + +class BatchAnnotateImagesResponse(proto.Message): + r"""Response to a batch image annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): + Individual responses to image annotation + requests within the batch. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageResponse', + ) + + +class AsyncAnnotateFileRequest(proto.Message): + r"""An offline file annotation request. + + Attributes: + input_config (google.cloud.vision_v1p3beta1.types.InputConfig): + Required. Information about the input file. + features (Sequence[google.cloud.vision_v1p3beta1.types.Feature]): + Required. Requested features. + image_context (google.cloud.vision_v1p3beta1.types.ImageContext): + Additional context that may accompany the + image(s) in the file. + output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): + Required. The desired output location and + metadata (e.g. format). + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + output_config = proto.Field( + proto.MESSAGE, + number=4, + message='OutputConfig', + ) + + +class AsyncAnnotateFileResponse(proto.Message): + r"""The response for a single offline file annotation request. + + Attributes: + output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): + The output location and metadata from + AsyncAnnotateFileRequest. + """ + + output_config = proto.Field( + proto.MESSAGE, + number=1, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateFilesRequest(proto.Message): + r"""Multiple async file annotation requests are batched into a + single service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]): + Required. Individual async file annotation + requests for this batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileRequest', + ) + + +class AsyncBatchAnnotateFilesResponse(proto.Message): + r"""Response to an async batch file annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileResponse]): + The list of file annotation responses, one + for each request in + AsyncBatchAnnotateFilesRequest. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileResponse', + ) + + +class InputConfig(proto.Message): + r"""The desired input location and metadata. + + Attributes: + gcs_source (google.cloud.vision_v1p3beta1.types.GcsSource): + The Google Cloud Storage location to read the + input from. + mime_type (str): + The type of the file. Currently only + "application/pdf" and "image/tiff" are + supported. Wildcards are not supported. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message='GcsSource', + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class OutputConfig(proto.Message): + r"""The desired output location and metadata. + + Attributes: + gcs_destination (google.cloud.vision_v1p3beta1.types.GcsDestination): + The Google Cloud Storage location to write + the output(s) to. + batch_size (int): + The max number of response protos to put into each output + JSON file 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 response + protos will be generated. If ``batch_size`` = 20, then 5 + json files each containing 20 response protos will be + written under the prefix ``gcs_destination``.\ ``uri``. + + Currently, batch_size only applies to GcsDestination, with + potential future support for other output configurations. + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message='GcsDestination', + ) + batch_size = proto.Field( + proto.INT32, + number=2, + ) + + +class GcsSource(proto.Message): + r"""The Google Cloud Storage location where the input will be + read from. + + Attributes: + uri (str): + Google Cloud Storage URI for the input file. + This must only be a Google Cloud Storage object. + Wildcards are not currently supported. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class GcsDestination(proto.Message): + r"""The Google Cloud Storage location where the output will be + written to. + + Attributes: + uri (str): + Google Cloud Storage URI where the results will be stored. + Results will be in JSON format and preceded by its + corresponding input URI. This field can either represent a + single file, or a prefix for multiple outputs. Prefixes must + end in a ``/``. + + Examples: + + - File: gs://bucket-name/filename.json + - Prefix: gs://bucket-name/prefix/here/ + - File: gs://bucket-name/prefix/here + + If multiple outputs, each response is still + AnnotateFileResponse, each of which contains some subset of + the full list of AnnotateImageResponse. Multiple outputs can + happen if, for example, the output JSON is too large and + overflows into multiple sharded files. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class OperationMetadata(proto.Message): + r"""Contains metadata for the BatchAnnotateImages operation. + + Attributes: + state (google.cloud.vision_v1p3beta1.types.OperationMetadata.State): + Current state of the batch operation. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was received. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the operation result was last + updated. + """ + class State(proto.Enum): + r"""Batch operation states.""" + STATE_UNSPECIFIED = 0 + CREATED = 1 + RUNNING = 2 + DONE = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py new file mode 100644 index 00000000..03097093 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py @@ -0,0 +1,249 @@ +# -*- 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.vision_v1p3beta1.types import geometry +from google.cloud.vision_v1p3beta1.types import product_search_service +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p3beta1', + manifest={ + 'ProductSearchCategory', + 'ProductSearchResultsView', + 'ProductSearchParams', + 'ProductSearchResults', + }, +) + + +class ProductSearchCategory(proto.Enum): + r"""Supported product search categories.""" + PRODUCT_SEARCH_CATEGORY_UNSPECIFIED = 0 + SHOES = 1 + BAGS = 2 + + +class ProductSearchResultsView(proto.Enum): + r"""Specifies the fields to include in product search results.""" + BASIC = 0 + FULL = 1 + + +class ProductSearchParams(proto.Message): + r"""Parameters for a product search request. + + Attributes: + catalog_name (str): + The resource name of the catalog to search. + + Format is: ``productSearch/catalogs/CATALOG_NAME``. + category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): + The category to search in. Optional. It is inferred by the + system if it is not specified. [Deprecated] Use + ``product_category``. + product_category (str): + The product category to search in. Optional. It is inferred + by the system if it is not specified. Supported values are + ``bag``, ``shoe``, ``sunglasses``, ``dress``, ``outerwear``, + ``skirt``, ``top``, ``shorts``, and ``pants``. + normalized_bounding_poly (google.cloud.vision_v1p3beta1.types.NormalizedBoundingPoly): + The bounding polygon around the area of interest in the + image. Optional. If it is not specified, system discretion + will be applied. [Deprecated] Use ``bounding_poly``. + bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding polygon around the area of + interest in the image. Optional. If it is not + specified, system discretion will be applied. + view (google.cloud.vision_v1p3beta1.types.ProductSearchResultsView): + Specifies the verbosity of the product search results. + Optional. Defaults to ``BASIC``. + product_set (str): + The resource name of a + [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] to be + searched for similar images. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. + product_categories (Sequence[str]): + The list of product categories to search in. + Currently, we only consider the first category, + and either "homegoods" or "apparel" should be + specified. + filter (str): + The filtering expression. This can be used to + restrict search results based on Product labels. + We currently support an AND of OR of key-value + expressions, where each expression within an OR + must have the same key. + For example, "(color = red OR color = blue) AND + brand = Google" is acceptable, but not "(color = + red OR brand = Google)" or "color: red". + """ + + catalog_name = proto.Field( + proto.STRING, + number=1, + ) + category = proto.Field( + proto.ENUM, + number=2, + enum='ProductSearchCategory', + ) + product_category = proto.Field( + proto.STRING, + number=5, + ) + normalized_bounding_poly = proto.Field( + proto.MESSAGE, + number=3, + message=geometry.NormalizedBoundingPoly, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=9, + message=geometry.BoundingPoly, + ) + view = proto.Field( + proto.ENUM, + number=4, + enum='ProductSearchResultsView', + ) + product_set = proto.Field( + proto.STRING, + number=6, + ) + product_categories = proto.RepeatedField( + proto.STRING, + number=7, + ) + filter = proto.Field( + proto.STRING, + number=8, + ) + + +class ProductSearchResults(proto.Message): + r"""Results for a product search request. + + Attributes: + category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): + Product category. [Deprecated] Use ``product_category``. + product_category (str): + Product category. Supported values are ``bag`` and ``shoe``. + [Deprecated] ``product_category`` is provided in each + Product. + index_time (google.protobuf.timestamp_pb2.Timestamp): + Timestamp of the index which provided these + results. Changes made after this time are not + reflected in the current results. + products (Sequence[google.cloud.vision_v1p3beta1.types.ProductSearchResults.ProductInfo]): + List of detected products. + results (Sequence[google.cloud.vision_v1p3beta1.types.ProductSearchResults.Result]): + List of results, one for each product match. + """ + + class ProductInfo(proto.Message): + r"""Information about a product. + + Attributes: + product_id (str): + Product ID. + image_uri (str): + The URI of the image which matched the query image. + + This field is returned only if ``view`` is set to ``FULL`` + in the request. + score (float): + A confidence level on the match, ranging from 0 (no + confidence) to 1 (full confidence). + + This field is returned only if ``view`` is set to ``FULL`` + in the request. + """ + + product_id = proto.Field( + proto.STRING, + number=1, + ) + image_uri = proto.Field( + proto.STRING, + number=2, + ) + score = proto.Field( + proto.FLOAT, + number=3, + ) + + class Result(proto.Message): + r"""Information about a product. + + Attributes: + product (google.cloud.vision_v1p3beta1.types.Product): + The Product. + score (float): + A confidence level on the match, ranging from 0 (no + confidence) to 1 (full confidence). + + This field is returned only if ``view`` is set to ``FULL`` + in the request. + image (str): + The resource name of the image from the + product that is the closest match to the query. + """ + + product = proto.Field( + proto.MESSAGE, + number=1, + message=product_search_service.Product, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + image = proto.Field( + proto.STRING, + number=3, + ) + + category = proto.Field( + proto.ENUM, + number=1, + enum='ProductSearchCategory', + ) + product_category = proto.Field( + proto.STRING, + number=4, + ) + index_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + products = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=ProductInfo, + ) + results = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Result, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py new file mode 100644 index 00000000..c3b3d8be --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py @@ -0,0 +1,998 @@ +# -*- 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.vision_v1p3beta1.types import geometry +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p3beta1', + manifest={ + 'Product', + 'ProductSet', + 'ReferenceImage', + 'CreateProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'GetProductRequest', + 'UpdateProductRequest', + 'DeleteProductRequest', + 'CreateProductSetRequest', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'GetProductSetRequest', + 'UpdateProductSetRequest', + 'DeleteProductSetRequest', + 'CreateReferenceImageRequest', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'GetReferenceImageRequest', + 'DeleteReferenceImageRequest', + 'AddProductToProductSetRequest', + 'RemoveProductFromProductSetRequest', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'BatchOperationMetadata', + }, +) + + +class Product(proto.Message): + r"""A Product contains ReferenceImages. + + Attributes: + name (str): + The resource name of the product. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This field is ignored when creating a product. + display_name (str): + The user-provided name for this Product. Must + not be empty. Must be at most 4096 characters + long. + description (str): + User-provided metadata to be stored with this + product. Must be at most 4096 characters long. + product_category (str): + Immutable. The category for the product + identified by the reference image. This should + be either "homegoods-v2", "apparel-v2", or + "toys-v2". The legacy categories "homegoods", + "apparel", and "toys" are still supported, but + these should not be used for new products. + product_labels (Sequence[google.cloud.vision_v1p3beta1.types.Product.KeyValue]): + Key-value pairs that can be attached to a product. At query + time, constraints can be specified based on the + product_labels. + + Note that integer values can be provided as strings, e.g. + "1199". Only strings with integer values can match a + range-based restriction which is to be supported soon. + + Multiple values can be assigned to the same key. One product + may have up to 100 product_labels. + """ + + class KeyValue(proto.Message): + r"""A product label represented as a key-value pair. + + Attributes: + key (str): + The key of the label attached to the product. + Cannot be empty and cannot exceed 128 bytes. + value (str): + The value of the label attached to the + product. Cannot be empty and cannot exceed 128 + bytes. + """ + + key = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + product_category = proto.Field( + proto.STRING, + number=4, + ) + product_labels = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=KeyValue, + ) + + +class ProductSet(proto.Message): + r"""A ProductSet contains Products. A ProductSet can contain a + maximum of 1 million reference images. If the limit is exceeded, + periodic indexing will fail. + + Attributes: + name (str): + The resource name of the ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. + + This field is ignored when creating a ProductSet. + display_name (str): + The user-provided name for this ProductSet. + Must not be empty. Must be at most 4096 + characters long. + index_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which this + ProductSet was last indexed. Query results will + reflect all updates before this time. If this + ProductSet has never been indexed, this field is + 0. + + This field is ignored when creating a + ProductSet. + index_error (google.rpc.status_pb2.Status): + Output only. If there was an error with + indexing the product set, the field is + populated. + This field is ignored when creating a + ProductSet. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + index_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + index_error = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + + +class ReferenceImage(proto.Message): + r"""A ``ReferenceImage`` represents a product image and its associated + metadata, such as bounding boxes. + + Attributes: + name (str): + The resource name of the reference image. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + This field is ignored when creating a reference image. + uri (str): + Required. The Google Cloud Storage URI of the reference + image. + + The URI must start with ``gs://``. + bounding_polys (Sequence[google.cloud.vision_v1p3beta1.types.BoundingPoly]): + Optional. Bounding polygons around the areas + of interest in the reference image. If this + field is empty, the system will try to detect + regions of interest. At most 10 bounding + polygons will be used. + The provided shape is converted into a non- + rotated rectangle. Once converted, the small + edge of the rectangle must be greater than or + equal to 300 pixels. The aspect ratio must be + 1:4 or less (i.e. 1:3 is ok; 1:5 is not). + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + uri = proto.Field( + proto.STRING, + number=2, + ) + bounding_polys = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, + ) + + +class CreateProductRequest(proto.Message): + r"""Request message for the ``CreateProduct`` method. + + Attributes: + parent (str): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + product (google.cloud.vision_v1p3beta1.types.Product): + Required. The product to create. + product_id (str): + A user-supplied resource id for this Product. If set, the + server will attempt to use this value as the resource id. If + it is already in use, an error is returned with code + ALREADY_EXISTS. Must be at most 128 characters long. It + cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.MESSAGE, + number=2, + message='Product', + ) + product_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsRequest(proto.Message): + r"""Request message for the ``ListProducts`` method. + + Attributes: + parent (str): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsResponse(proto.Message): + r"""Response message for the ``ListProducts`` method. + + Attributes: + products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): + List of products. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + products = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetProductRequest(proto.Message): + r"""Request message for the ``GetProduct`` method. + + Attributes: + name (str): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateProductRequest(proto.Message): + r"""Request message for the ``UpdateProduct`` method. + + Attributes: + product (google.cloud.vision_v1p3beta1.types.Product): + Required. The Product resource which replaces + the one on the server. product.name is + immutable. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that specifies + which fields to update. If update_mask isn't specified, all + mutable fields are to be updated. Valid mask paths include + ``product_labels``, ``display_name``, and ``description``. + """ + + product = proto.Field( + proto.MESSAGE, + number=1, + message='Product', + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteProductRequest(proto.Message): + r"""Request message for the ``DeleteProduct`` method. + + Attributes: + name (str): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateProductSetRequest(proto.Message): + r"""Request message for the ``CreateProductSet`` method. + + Attributes: + parent (str): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): + Required. The ProductSet to create. + product_set_id (str): + A user-supplied resource id for this ProductSet. If set, the + server will attempt to use this value as the resource id. If + it is already in use, an error is returned with code + ALREADY_EXISTS. Must be at most 128 characters long. It + cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + product_set = proto.Field( + proto.MESSAGE, + number=2, + message='ProductSet', + ) + product_set_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductSetsRequest(proto.Message): + r"""Request message for the ``ListProductSets`` method. + + Attributes: + parent (str): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductSetsResponse(proto.Message): + r"""Response message for the ``ListProductSets`` method. + + Attributes: + product_sets (Sequence[google.cloud.vision_v1p3beta1.types.ProductSet]): + List of ProductSets. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + product_sets = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ProductSet', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetProductSetRequest(proto.Message): + r"""Request message for the ``GetProductSet`` method. + + Attributes: + name (str): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateProductSetRequest(proto.Message): + r"""Request message for the ``UpdateProductSet`` method. + + Attributes: + product_set (google.cloud.vision_v1p3beta1.types.ProductSet): + Required. The ProductSet resource which + replaces the one on the server. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that specifies + which fields to update. If update_mask isn't specified, all + mutable fields are to be updated. Valid mask path is + ``display_name``. + """ + + product_set = proto.Field( + proto.MESSAGE, + number=1, + message='ProductSet', + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteProductSetRequest(proto.Message): + r"""Request message for the ``DeleteProductSet`` method. + + Attributes: + name (str): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateReferenceImageRequest(proto.Message): + r"""Request message for the ``CreateReferenceImage`` method. + + Attributes: + parent (str): + Required. Resource name of the product in which to create + the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + reference_image (google.cloud.vision_v1p3beta1.types.ReferenceImage): + Required. The reference image to create. + If an image ID is specified, it is ignored. + reference_image_id (str): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value as + the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + reference_image = proto.Field( + proto.MESSAGE, + number=2, + message='ReferenceImage', + ) + reference_image_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListReferenceImagesRequest(proto.Message): + r"""Request message for the ``ListReferenceImages`` method. + + Attributes: + parent (str): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + A token identifying a page of results to be returned. This + is the value of ``nextPageToken`` returned in a previous + reference image list request. + + Defaults to the first page if not specified. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListReferenceImagesResponse(proto.Message): + r"""Response message for the ``ListReferenceImages`` method. + + Attributes: + reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): + The list of reference images. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + next_page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + @property + def raw_page(self): + return self + + reference_images = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ReferenceImage', + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + next_page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class GetReferenceImageRequest(proto.Message): + r"""Request message for the ``GetReferenceImage`` method. + + Attributes: + name (str): + Required. The resource name of the ReferenceImage to get. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteReferenceImageRequest(proto.Message): + r"""Request message for the ``DeleteReferenceImage`` method. + + Attributes: + name (str): + Required. The resource name of the reference image to + delete. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class AddProductToProductSetRequest(proto.Message): + r"""Request message for the ``AddProductToProductSet`` method. + + Attributes: + name (str): + Required. The resource name for the ProductSet to modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + product (str): + Required. The resource name for the Product to be added to + this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.STRING, + number=2, + ) + + +class RemoveProductFromProductSetRequest(proto.Message): + r"""Request message for the ``RemoveProductFromProductSet`` method. + + Attributes: + name (str): + Required. The resource name for the ProductSet to modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + product (str): + Required. The resource name for the Product to be removed + from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.STRING, + number=2, + ) + + +class ListProductsInProductSetRequest(proto.Message): + r"""Request message for the ``ListProductsInProductSet`` method. + + Attributes: + name (str): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsInProductSetResponse(proto.Message): + r"""Response message for the ``ListProductsInProductSet`` method. + + Attributes: + products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): + The list of Products. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + products = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class ImportProductSetsGcsSource(proto.Message): + r"""The Google Cloud Storage location for a csv file which + preserves a list of ImportProductSetRequests in each line. + + Attributes: + csv_file_uri (str): + The Google Cloud Storage URI of the input csv file. + + The URI must start with ``gs://``. + + The format of the input csv file should be one image per + line. In each line, there are 6 columns. + + 1. image_uri 2, image_id + 2. product_set_id + 3. product_id 5, product_category 6, product_display_name 7, + labels + 4. bounding_poly + + Columns 1, 3, 4, and 5 are required, other columns are + optional. A new ProductSet/Product with the same id will be + created on the fly if the ProductSet/Product specified by + product_set_id/product_id does not exist. + + The image_id field is optional but has to be unique if + provided. If it is empty, we will automatically assign an + unique id to the image. + + The product_display_name field is optional. If it is empty, + a space (" ") is used as the place holder for the product + display_name, which can be updated later through the + realtime API. + + If the Product with product_id already exists, the fields + product_display_name, product_category and labels are + ignored. + + If a Product doesn't exist and needs to be created on the + fly, the product_display_name field refers to + [Product.display_name][google.cloud.vision.v1p3beta1.Product.display_name], + the product_category field refers to + [Product.product_category][google.cloud.vision.v1p3beta1.Product.product_category], + and the labels field refers to [Product.labels][]. + + Labels (optional) should be a line containing a list of + comma-separated key-value pairs, with the format + "key_1=value_1,key_2=value_2,...,key_n=value_n". + + The bounding_poly (optional) field is used to identify one + region of interest from the image in the same manner as + CreateReferenceImage. If no bounding_poly is specified, the + system will try to detect regions of interest automatically. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 20MP). + + Also note that at most one bounding_poly is allowed per + line. If the image contains multiple regions of interest, + the csv should contain one line per region of interest. + + The bounding_poly column should contain an even number of + comma-separated numbers, with the format + "p1_x,p1_y,p2_x,p2_y,...,pn_x,pn_y". Nonnegative integers + should be used for absolute bounding polygons, and float + values in [0, 1] should be used for normalized bounding + polygons. + """ + + csv_file_uri = proto.Field( + proto.STRING, + number=1, + ) + + +class ImportProductSetsInputConfig(proto.Message): + r"""The input content for the ``ImportProductSets`` method. + + Attributes: + gcs_source (google.cloud.vision_v1p3beta1.types.ImportProductSetsGcsSource): + The Google Cloud Storage location for a csv + file which preserves a list of + ImportProductSetRequests in each line. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + oneof='source', + message='ImportProductSetsGcsSource', + ) + + +class ImportProductSetsRequest(proto.Message): + r"""Request message for the ``ImportProductSets`` method. + + Attributes: + parent (str): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + input_config (google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig): + Required. The input content for the list of + requests. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + input_config = proto.Field( + proto.MESSAGE, + number=2, + message='ImportProductSetsInputConfig', + ) + + +class ImportProductSetsResponse(proto.Message): + r"""Response message for the ``ImportProductSets`` method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + Attributes: + reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): + The list of reference_images that are imported successfully. + statuses (Sequence[google.rpc.status_pb2.Status]): + The rpc status for each ImportProductSet request, including + both successes and errors. + + The number of statuses here matches the number of lines in + the csv file, and statuses[i] stores the success or failure + status of processing the i-th line of the csv, starting from + line 0. + """ + + reference_images = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ReferenceImage', + ) + statuses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + + +class BatchOperationMetadata(proto.Message): + r"""Metadata for the batch operations such as the current state. + + This is included in the ``metadata`` field of the ``Operation`` + returned by the ``GetOperation`` call of the + ``google::longrunning::Operations`` service. + + Attributes: + state (google.cloud.vision_v1p3beta1.types.BatchOperationMetadata.State): + The current state of the batch operation. + submit_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was submitted + to the server. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request is finished and + [google.longrunning.Operation.done][google.longrunning.Operation.done] + is set to true. + """ + class State(proto.Enum): + r"""Enumerates the possible states that the batch request can be + in. + """ + STATE_UNSPECIFIED = 0 + PROCESSING = 1 + SUCCESSFUL = 2 + FAILED = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + submit_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py new file mode 100644 index 00000000..1cc4ec5b --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py @@ -0,0 +1,393 @@ +# -*- 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.vision_v1p3beta1.types import geometry + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p3beta1', + manifest={ + 'TextAnnotation', + 'Page', + 'Block', + 'Paragraph', + 'Word', + 'Symbol', + }, +) + + +class TextAnnotation(proto.Message): + r"""TextAnnotation contains a structured representation of OCR extracted + text. The hierarchy of an OCR extracted text structure is like this: + TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each + structural component, starting from Page, may further have their own + properties. Properties describe detected languages, breaks etc.. + Please refer to the + [TextAnnotation.TextProperty][google.cloud.vision.v1p3beta1.TextAnnotation.TextProperty] + message definition below for more detail. + + Attributes: + pages (Sequence[google.cloud.vision_v1p3beta1.types.Page]): + List of pages detected by OCR. + text (str): + UTF-8 text detected on the pages. + """ + + 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, + ) + + class DetectedBreak(proto.Message): + r"""Detected start or end of a structural component. + + Attributes: + type_ (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak.BreakType): + Detected break type. + is_prefix (bool): + True if break prepends the element. + """ + class BreakType(proto.Enum): + r"""Enum to denote the type of break found. New line, space etc.""" + UNKNOWN = 0 + SPACE = 1 + SURE_SPACE = 2 + EOL_SURE_SPACE = 3 + HYPHEN = 4 + LINE_BREAK = 5 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='TextAnnotation.DetectedBreak.BreakType', + ) + is_prefix = proto.Field( + proto.BOOL, + number=2, + ) + + class TextProperty(proto.Message): + r"""Additional information detected on the structural component. + + Attributes: + detected_languages (Sequence[google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedLanguage]): + A list of detected languages together with + confidence. + detected_break (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak): + Detected start or end of a text segment. + """ + + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='TextAnnotation.DetectedLanguage', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='TextAnnotation.DetectedBreak', + ) + + pages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Page', + ) + text = proto.Field( + proto.STRING, + number=2, + ) + + +class Page(proto.Message): + r"""Detected page from OCR. + + Attributes: + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): + Additional information detected on the page. + width (int): + Page width. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + height (int): + Page height. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + blocks (Sequence[google.cloud.vision_v1p3beta1.types.Block]): + List of blocks of text, images etc on this + page. + confidence (float): + Confidence of the OCR results on the page. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + width = proto.Field( + proto.INT32, + number=2, + ) + height = proto.Field( + proto.INT32, + number=3, + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Block', + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Block(proto.Message): + r"""Logical element on the page. + + Attributes: + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + block. + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding box for the block. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: + + :: + + 0----1 + | | + 3----2 + + - when it's rotated 180 degrees around the top-left corner + it becomes: + + :: + + 2----3 + | | + 1----0 + + and the vertice order will still be (0, 1, 2, 3). + paragraphs (Sequence[google.cloud.vision_v1p3beta1.types.Paragraph]): + List of paragraphs in this block (if this + blocks is of type text). + block_type (google.cloud.vision_v1p3beta1.types.Block.BlockType): + Detected block type (text, image etc) for + this block. + confidence (float): + Confidence of the OCR results on the block. Range [0, 1]. + """ + class BlockType(proto.Enum): + r"""Type of a block (text, image etc) as identified by OCR.""" + UNKNOWN = 0 + TEXT = 1 + TABLE = 2 + PICTURE = 3 + RULER = 4 + BARCODE = 5 + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Paragraph', + ) + block_type = proto.Field( + proto.ENUM, + number=4, + enum=BlockType, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Paragraph(proto.Message): + r"""Structural unit of text representing a number of words in + certain order. + + Attributes: + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + paragraph. + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding box for the paragraph. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + words (Sequence[google.cloud.vision_v1p3beta1.types.Word]): + List of words in this paragraph. + confidence (float): + Confidence of the OCR results for the paragraph. Range [0, + 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + words = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Word', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Word(proto.Message): + r"""A word representation. + + Attributes: + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): + Additional information detected for the word. + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding box for the word. The vertices are in the order + of top-left, top-right, bottom-right, bottom-left. When a + rotation of the bounding box is detected the rotation is + represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + symbols (Sequence[google.cloud.vision_v1p3beta1.types.Symbol]): + List of symbols in the word. + The order of the symbols follows the natural + reading order. + confidence (float): + Confidence of the OCR results for the word. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + symbols = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Symbol', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Symbol(proto.Message): + r"""A single symbol representation. + + Attributes: + property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + symbol. + bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): + The bounding box for the symbol. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertice order + will still be (0, 1, 2, 3). + text (str): + The actual UTF-8 representation of the + symbol. + confidence (float): + Confidence of the OCR results for the symbol. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + text = proto.Field( + proto.STRING, + number=3, + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py new file mode 100644 index 00000000..903d0ce4 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py @@ -0,0 +1,199 @@ +# -*- 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.vision.v1p3beta1', + manifest={ + 'WebDetection', + }, +) + + +class WebDetection(proto.Message): + r"""Relevant information for the image from the Internet. + + Attributes: + web_entities (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebEntity]): + Deduced entities from similar images on the + Internet. + full_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): + Fully matching images from the Internet. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): + Partial matching images from the Internet. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + pages_with_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebPage]): + Web pages containing the matching images from + the Internet. + visually_similar_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): + The visually similar image results. + best_guess_labels (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebLabel]): + Best guess text labels for the request image. + """ + + class WebEntity(proto.Message): + r"""Entity deduced from similar images on the Internet. + + Attributes: + entity_id (str): + Opaque entity ID. + score (float): + Overall relevancy score for the entity. + Not normalized and not comparable across + different image queries. + description (str): + Canonical description of the entity, in + English. + """ + + entity_id = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + + class WebImage(proto.Message): + r"""Metadata for online images. + + Attributes: + url (str): + The result image URL. + score (float): + (Deprecated) Overall relevancy score for the + image. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + + class WebPage(proto.Message): + r"""Metadata for web pages. + + Attributes: + url (str): + The result web page URL. + score (float): + (Deprecated) Overall relevancy score for the + web page. + page_title (str): + Title for the web page, may contain HTML + markups. + full_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): + Fully matching images on the page. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): + Partial matching images on the page. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + page_title = proto.Field( + proto.STRING, + number=3, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='WebDetection.WebImage', + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='WebDetection.WebImage', + ) + + class WebLabel(proto.Message): + r"""Label to provide extra metadata for the web detection. + + Attributes: + label (str): + Label for extra metadata. + language_code (str): + The BCP-47 language code for ``label``, such as "en-US" or + "sr-Latn". For more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + """ + + label = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + + web_entities = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=WebEntity, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=WebImage, + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=WebImage, + ) + pages_with_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=WebPage, + ) + visually_similar_images = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=WebImage, + ) + best_guess_labels = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=WebLabel, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/mypy.ini b/owl-bot-staging/v1p3beta1/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1p3beta1/noxfile.py b/owl-bot-staging/v1p3beta1/noxfile.py new file mode 100644 index 00000000..4c77be9c --- /dev/null +++ b/owl-bot-staging/v1p3beta1/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/vision_v1p3beta1/', + '--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/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py b/owl-bot-staging/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py new file mode 100644 index 00000000..962a0f93 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py @@ -0,0 +1,195 @@ +#! /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 visionCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'add_product_to_product_set': ('name', 'product', ), + 'async_batch_annotate_files': ('requests', ), + 'batch_annotate_images': ('requests', ), + 'create_product': ('parent', 'product', 'product_id', ), + 'create_product_set': ('parent', 'product_set', 'product_set_id', ), + 'create_reference_image': ('parent', 'reference_image', 'reference_image_id', ), + 'delete_product': ('name', ), + 'delete_product_set': ('name', ), + 'delete_reference_image': ('name', ), + 'get_product': ('name', ), + 'get_product_set': ('name', ), + 'get_reference_image': ('name', ), + 'import_product_sets': ('parent', 'input_config', ), + 'list_products': ('parent', 'page_size', 'page_token', ), + 'list_product_sets': ('parent', 'page_size', 'page_token', ), + 'list_products_in_product_set': ('name', 'page_size', 'page_token', ), + 'list_reference_images': ('parent', 'page_size', 'page_token', ), + 'remove_product_from_product_set': ('name', 'product', ), + 'update_product': ('product', 'update_mask', ), + 'update_product_set': ('product_set', 'update_mask', ), + } + + 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: a.keyword.value not 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=visionCallTransformer(), +): + """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 vision 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/v1p3beta1/setup.py b/owl-bot-staging/v1p3beta1/setup.py new file mode 100644 index 00000000..9d03e702 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/setup.py @@ -0,0 +1,54 @@ +# -*- 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-vision', + 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, < 3.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', + 'Programming Language :: Python :: 3.9', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1p3beta1/tests/__init__.py b/owl-bot-staging/v1p3beta1/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p3beta1/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/v1p3beta1/tests/unit/__init__.py b/owl-bot-staging/v1p3beta1/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p3beta1/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/v1p3beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p3beta1/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/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__init__.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__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/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py new file mode 100644 index 00000000..fcabadc9 --- /dev/null +++ b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py @@ -0,0 +1,1385 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1p3beta1.services.image_annotator import ImageAnnotatorAsyncClient +from google.cloud.vision_v1p3beta1.services.image_annotator import ImageAnnotatorClient +from google.cloud.vision_v1p3beta1.services.image_annotator import transports +from google.cloud.vision_v1p3beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1p3beta1.types import geometry +from google.cloud.vision_v1p3beta1.types import image_annotator +from google.cloud.vision_v1p3beta1.types import product_search +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ImageAnnotatorGrpcTransport, "grpc"), + (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +def test_image_annotator_client_get_transport_class(): + transport = ImageAnnotatorClient.get_transport_class() + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports + + transport = ImageAnnotatorClient.get_transport_class("grpc") + assert transport == transports.ImageAnnotatorGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + +def test_image_annotator_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ImageAnnotatorClient( + 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, + always_use_jwt_access=True, + ) + + +def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse( + ) + response = client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +def test_batch_annotate_images_from_dict(): + test_batch_annotate_images(request_type=dict) + + +def test_batch_annotate_images_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 = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + client.batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( + )) + response = await client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async_from_dict(): + await test_batch_annotate_images_async(request_type=dict) + + +def test_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +def test_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_async_batch_annotate_files_from_dict(): + test_async_batch_annotate_files(request_type=dict) + + +def test_async_batch_annotate_files_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 = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + client.async_batch_annotate_files() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files), + '__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.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async_from_dict(): + await test_async_batch_annotate_files_async(request_type=dict) + + +def test_async_batch_annotate_files_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +def test_async_batch_annotate_files_flattened_error(): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ImageAnnotatorClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, +]) +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 = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ImageAnnotatorGrpcTransport, + ) + +def test_image_annotator_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_image_annotator_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'batch_annotate_images', + 'async_batch_annotate_files', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ImageAnnotatorGrpcTransport, grpc_helpers), + (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_image_annotator_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_host_no_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_image_annotator_host_with_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_image_annotator_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcTransport( + 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_image_annotator_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_grpc_lro_client(): + client = ImageAnnotatorClient( + 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_image_annotator_grpc_lro_async_client(): + client = ImageAnnotatorAsyncClient( + 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_product_path(): + project = "squid" + location = "clam" + product = "whelk" + expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + actual = ImageAnnotatorClient.product_path(project, location, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "project": "octopus", + "location": "oyster", + "product": "nudibranch", + } + path = ImageAnnotatorClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_product_path(path) + assert expected == actual + +def test_product_set_path(): + project = "cuttlefish" + location = "mussel" + product_set = "winkle" + expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + actual = ImageAnnotatorClient.product_set_path(project, location, product_set) + assert expected == actual + + +def test_parse_product_set_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "product_set": "abalone", + } + path = ImageAnnotatorClient.product_set_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_product_set_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ImageAnnotatorClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ImageAnnotatorClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = ImageAnnotatorClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ImageAnnotatorClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ImageAnnotatorClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ImageAnnotatorClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = ImageAnnotatorClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ImageAnnotatorClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ImageAnnotatorClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + transport_class = ImageAnnotatorClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py new file mode 100644 index 00000000..eff5548f --- /dev/null +++ b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py @@ -0,0 +1,6093 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1p3beta1.services.product_search import ProductSearchAsyncClient +from google.cloud.vision_v1p3beta1.services.product_search import ProductSearchClient +from google.cloud.vision_v1p3beta1.services.product_search import pagers +from google.cloud.vision_v1p3beta1.services.product_search import transports +from google.cloud.vision_v1p3beta1.services.product_search.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1p3beta1.types import geometry +from google.cloud.vision_v1p3beta1.types import product_search_service +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +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 ProductSearchClient._get_default_mtls_endpoint(None) is None + assert ProductSearchClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ProductSearchClient, + ProductSearchAsyncClient, +]) +def test_product_search_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductSearchGrpcTransport, "grpc"), + (transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ProductSearchClient, + ProductSearchAsyncClient, +]) +def test_product_search_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 == 'vision.googleapis.com:443' + + +def test_product_search_client_get_transport_class(): + transport = ProductSearchClient.get_transport_class() + available_transports = [ + transports.ProductSearchGrpcTransport, + ] + assert transport in available_transports + + transport = ProductSearchClient.get_transport_class("grpc") + assert transport == transports.ProductSearchGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) +@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) +def test_product_search_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(ProductSearchClient, '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(ProductSearchClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "true"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "false"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) +@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_product_search_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_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, + always_use_jwt_access=True, + ) + + +def test_product_search_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductSearchClient( + 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, + always_use_jwt_access=True, + ) + + +def test_create_product_set(transport: str = 'grpc', request_type=product_search_service.CreateProductSetRequest): + client = ProductSearchClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.create_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_create_product_set_from_dict(): + test_create_product_set(request_type=dict) + + +def test_create_product_set_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 = ProductSearchClient( + 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_product_set), + '__call__') as call: + client.create_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + +@pytest.mark.asyncio +async def test_create_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductSetRequest): + client = ProductSearchAsyncClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.create_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_create_product_set_async_from_dict(): + await test_create_product_set_async(request_type=dict) + + +def test_create_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateProductSetRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.create_product_set(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_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateProductSetRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.create_product_set(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_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_product_set( + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].product_set_id == 'product_set_id_value' + + +def test_create_product_set_flattened_error(): + client = ProductSearchClient( + 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_product_set( + product_search_service.CreateProductSetRequest(), + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_product_set( + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].product_set_id == 'product_set_id_value' + + +@pytest.mark.asyncio +async def test_create_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_set( + product_search_service.CreateProductSetRequest(), + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_value', + ) + + +def test_list_product_sets(transport: str = 'grpc', request_type=product_search_service.ListProductSetsRequest): + client = ProductSearchClient( + 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_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductSetsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_product_sets_from_dict(): + test_list_product_sets(request_type=dict) + + +def test_list_product_sets_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 = ProductSearchClient( + 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_product_sets), + '__call__') as call: + client.list_product_sets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + +@pytest.mark.asyncio +async def test_list_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductSetsRequest): + client = ProductSearchAsyncClient( + 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_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductSetsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_product_sets_async_from_dict(): + await test_list_product_sets_async(request_type=dict) + + +def test_list_product_sets_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + call.return_value = product_search_service.ListProductSetsResponse() + client.list_product_sets(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_product_sets_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) + await client.list_product_sets(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_product_sets_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_product_sets( + 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_product_sets_flattened_error(): + client = ProductSearchClient( + 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_product_sets( + product_search_service.ListProductSetsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_product_sets_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_product_sets( + 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_product_sets_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_sets( + product_search_service.ListProductSetsRequest(), + parent='parent_value', + ) + + +def test_list_product_sets_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_product_sets(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.ProductSet) + for i in results) + +def test_list_product_sets_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + pages = list(client.list_product_sets(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_product_sets_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_product_sets(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, product_search_service.ProductSet) + for i in responses) + +@pytest.mark.asyncio +async def test_list_product_sets_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_product_sets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_product_set(transport: str = 'grpc', request_type=product_search_service.GetProductSetRequest): + client = ProductSearchClient( + 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.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.get_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_get_product_set_from_dict(): + test_get_product_set(request_type=dict) + + +def test_get_product_set_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 = ProductSearchClient( + 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.get_product_set), + '__call__') as call: + client.get_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + +@pytest.mark.asyncio +async def test_get_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductSetRequest): + client = ProductSearchAsyncClient( + 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.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.get_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_get_product_set_async_from_dict(): + await test_get_product_set_async(request_type=dict) + + +def test_get_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.get_product_set(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_get_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.get_product_set(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_get_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product_set( + 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_get_product_set_flattened_error(): + client = ProductSearchClient( + 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.get_product_set( + product_search_service.GetProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product_set( + 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_get_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_product_set( + product_search_service.GetProductSetRequest(), + name='name_value', + ) + + +def test_update_product_set(transport: str = 'grpc', request_type=product_search_service.UpdateProductSetRequest): + client = ProductSearchClient( + 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.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.update_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_update_product_set_from_dict(): + test_update_product_set(request_type=dict) + + +def test_update_product_set_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 = ProductSearchClient( + 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.update_product_set), + '__call__') as call: + client.update_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + +@pytest.mark.asyncio +async def test_update_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductSetRequest): + client = ProductSearchAsyncClient( + 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.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.update_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_update_product_set_async_from_dict(): + await test_update_product_set_async(request_type=dict) + + +def test_update_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.UpdateProductSetRequest() + + request.product_set.name = 'product_set.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.update_product_set(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', + 'product_set.name=product_set.name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.UpdateProductSetRequest() + + request.product_set.name = 'product_set.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.update_product_set(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', + 'product_set.name=product_set.name/value', + ) in kw['metadata'] + + +def test_update_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product_set( + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +def test_update_product_set_flattened_error(): + client = ProductSearchClient( + 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.update_product_set( + product_search_service.UpdateProductSetRequest(), + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.asyncio +async def test_update_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product_set( + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +@pytest.mark.asyncio +async def test_update_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.update_product_set( + product_search_service.UpdateProductSetRequest(), + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product_set(transport: str = 'grpc', request_type=product_search_service.DeleteProductSetRequest): + client = ProductSearchClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_set_from_dict(): + test_delete_product_set(request_type=dict) + + +def test_delete_product_set_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 = ProductSearchClient( + 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_product_set), + '__call__') as call: + client.delete_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + +@pytest.mark.asyncio +async def test_delete_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductSetRequest): + client = ProductSearchAsyncClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_set_async_from_dict(): + await test_delete_product_set_async(request_type=dict) + + +def test_delete_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + call.return_value = None + client.delete_product_set(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_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_set(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_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product_set( + 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_product_set_flattened_error(): + client = ProductSearchClient( + 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_product_set( + product_search_service.DeleteProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product_set( + 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_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_set( + product_search_service.DeleteProductSetRequest(), + name='name_value', + ) + + +def test_create_product(transport: str = 'grpc', request_type=product_search_service.CreateProductRequest): + client = ProductSearchClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.create_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_create_product_from_dict(): + test_create_product(request_type=dict) + + +def test_create_product_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 = ProductSearchClient( + 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_product), + '__call__') as call: + client.create_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + +@pytest.mark.asyncio +async def test_create_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductRequest): + client = ProductSearchAsyncClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.create_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_create_product_async_from_dict(): + await test_create_product_async(request_type=dict) + + +def test_create_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateProductRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.create_product(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_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateProductRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.create_product(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_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_product( + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_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].product == product_search_service.Product(name='name_value') + assert args[0].product_id == 'product_id_value' + + +def test_create_product_flattened_error(): + client = ProductSearchClient( + 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_product( + product_search_service.CreateProductRequest(), + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_product( + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_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].product == product_search_service.Product(name='name_value') + assert args[0].product_id == 'product_id_value' + + +@pytest.mark.asyncio +async def test_create_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product( + product_search_service.CreateProductRequest(), + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_value', + ) + + +def test_list_products(transport: str = 'grpc', request_type=product_search_service.ListProductsRequest): + client = ProductSearchClient( + 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_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_from_dict(): + test_list_products(request_type=dict) + + +def test_list_products_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 = ProductSearchClient( + 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_products), + '__call__') as call: + client.list_products() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + +@pytest.mark.asyncio +async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsRequest): + client = ProductSearchAsyncClient( + 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_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_async_from_dict(): + await test_list_products_async(request_type=dict) + + +def test_list_products_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = product_search_service.ListProductsResponse() + client.list_products(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_products_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) + await client.list_products(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_products_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products( + 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_products_flattened_error(): + client = ProductSearchClient( + 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_products( + product_search_service.ListProductsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_products_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products( + 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_products_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_products( + product_search_service.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_products(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.Product) + for i in results) + +def test_list_products_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products(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_products_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products(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, product_search_service.Product) + for i in responses) + +@pytest.mark.asyncio +async def test_list_products_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_products(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_product(transport: str = 'grpc', request_type=product_search_service.GetProductRequest): + client = ProductSearchClient( + 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.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_get_product_from_dict(): + test_get_product(request_type=dict) + + +def test_get_product_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 = ProductSearchClient( + 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.get_product), + '__call__') as call: + client.get_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + +@pytest.mark.asyncio +async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductRequest): + client = ProductSearchAsyncClient( + 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.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_get_product_async_from_dict(): + await test_get_product_async(request_type=dict) + + +def test_get_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.get_product(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_get_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.get_product(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_get_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product( + 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_get_product_flattened_error(): + client = ProductSearchClient( + 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.get_product( + product_search_service.GetProductRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product( + 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_get_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_product( + product_search_service.GetProductRequest(), + name='name_value', + ) + + +def test_update_product(transport: str = 'grpc', request_type=product_search_service.UpdateProductRequest): + client = ProductSearchClient( + 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.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.update_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_update_product_from_dict(): + test_update_product(request_type=dict) + + +def test_update_product_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 = ProductSearchClient( + 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.update_product), + '__call__') as call: + client.update_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + +@pytest.mark.asyncio +async def test_update_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductRequest): + client = ProductSearchAsyncClient( + 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.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.update_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_update_product_async_from_dict(): + await test_update_product_async(request_type=dict) + + +def test_update_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.UpdateProductRequest() + + request.product.name = 'product.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.update_product(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', + 'product.name=product.name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.UpdateProductRequest() + + request.product.name = 'product.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.update_product(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', + 'product.name=product.name/value', + ) in kw['metadata'] + + +def test_update_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product( + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +def test_update_product_flattened_error(): + client = ProductSearchClient( + 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.update_product( + product_search_service.UpdateProductRequest(), + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.asyncio +async def test_update_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product( + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +@pytest.mark.asyncio +async def test_update_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.update_product( + product_search_service.UpdateProductRequest(), + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product(transport: str = 'grpc', request_type=product_search_service.DeleteProductRequest): + client = ProductSearchClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_from_dict(): + test_delete_product(request_type=dict) + + +def test_delete_product_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 = ProductSearchClient( + 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_product), + '__call__') as call: + client.delete_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + +@pytest.mark.asyncio +async def test_delete_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductRequest): + client = ProductSearchAsyncClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_async_from_dict(): + await test_delete_product_async(request_type=dict) + + +def test_delete_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + call.return_value = None + client.delete_product(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_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product(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_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product( + 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_product_flattened_error(): + client = ProductSearchClient( + 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_product( + product_search_service.DeleteProductRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product( + 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_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product( + product_search_service.DeleteProductRequest(), + name='name_value', + ) + + +def test_create_reference_image(transport: str = 'grpc', request_type=product_search_service.CreateReferenceImageRequest): + client = ProductSearchClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + ) + response = client.create_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +def test_create_reference_image_from_dict(): + test_create_reference_image(request_type=dict) + + +def test_create_reference_image_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 = ProductSearchClient( + 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_reference_image), + '__call__') as call: + client.create_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_create_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateReferenceImageRequest): + client = ProductSearchAsyncClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + )) + response = await client.create_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +@pytest.mark.asyncio +async def test_create_reference_image_async_from_dict(): + await test_create_reference_image_async(request_type=dict) + + +def test_create_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateReferenceImageRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + call.return_value = product_search_service.ReferenceImage() + client.create_reference_image(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_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateReferenceImageRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + await client.create_reference_image(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_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_reference_image( + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') + assert args[0].reference_image_id == 'reference_image_id_value' + + +def test_create_reference_image_flattened_error(): + client = ProductSearchClient( + 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_reference_image( + product_search_service.CreateReferenceImageRequest(), + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_reference_image( + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') + assert args[0].reference_image_id == 'reference_image_id_value' + + +@pytest.mark.asyncio +async def test_create_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_image( + product_search_service.CreateReferenceImageRequest(), + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_value', + ) + + +def test_delete_reference_image(transport: str = 'grpc', request_type=product_search_service.DeleteReferenceImageRequest): + client = ProductSearchClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_reference_image_from_dict(): + test_delete_reference_image(request_type=dict) + + +def test_delete_reference_image_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 = ProductSearchClient( + 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_reference_image), + '__call__') as call: + client.delete_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_delete_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteReferenceImageRequest): + client = ProductSearchAsyncClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_reference_image_async_from_dict(): + await test_delete_reference_image_async(request_type=dict) + + +def test_delete_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + call.return_value = None + client.delete_reference_image(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_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_reference_image(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_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_reference_image( + 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_reference_image_flattened_error(): + client = ProductSearchClient( + 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_reference_image( + product_search_service.DeleteReferenceImageRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_reference_image( + 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_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_image( + product_search_service.DeleteReferenceImageRequest(), + name='name_value', + ) + + +def test_list_reference_images(transport: str = 'grpc', request_type=product_search_service.ListReferenceImagesRequest): + client = ProductSearchClient( + 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_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse( + page_size=951, + next_page_token='next_page_token_value', + ) + response = client.list_reference_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReferenceImagesPager) + assert response.page_size == 951 + assert response.next_page_token == 'next_page_token_value' + + +def test_list_reference_images_from_dict(): + test_list_reference_images(request_type=dict) + + +def test_list_reference_images_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 = ProductSearchClient( + 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_reference_images), + '__call__') as call: + client.list_reference_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + +@pytest.mark.asyncio +async def test_list_reference_images_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListReferenceImagesRequest): + client = ProductSearchAsyncClient( + 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_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse( + page_size=951, + next_page_token='next_page_token_value', + )) + response = await client.list_reference_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReferenceImagesAsyncPager) + assert response.page_size == 951 + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_reference_images_async_from_dict(): + await test_list_reference_images_async(request_type=dict) + + +def test_list_reference_images_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListReferenceImagesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + call.return_value = product_search_service.ListReferenceImagesResponse() + client.list_reference_images(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_reference_images_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListReferenceImagesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) + await client.list_reference_images(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_reference_images_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_reference_images( + 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_reference_images_flattened_error(): + client = ProductSearchClient( + 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_reference_images( + product_search_service.ListReferenceImagesRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_reference_images_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_reference_images( + 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_reference_images_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_images( + product_search_service.ListReferenceImagesRequest(), + parent='parent_value', + ) + + +def test_list_reference_images_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_reference_images(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.ReferenceImage) + for i in results) + +def test_list_reference_images_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + pages = list(client.list_reference_images(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_reference_images_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_reference_images(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, product_search_service.ReferenceImage) + for i in responses) + +@pytest.mark.asyncio +async def test_list_reference_images_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_reference_images(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_reference_image(transport: str = 'grpc', request_type=product_search_service.GetReferenceImageRequest): + client = ProductSearchClient( + 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.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + ) + response = client.get_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +def test_get_reference_image_from_dict(): + test_get_reference_image(request_type=dict) + + +def test_get_reference_image_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 = ProductSearchClient( + 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.get_reference_image), + '__call__') as call: + client.get_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_get_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetReferenceImageRequest): + client = ProductSearchAsyncClient( + 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.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + )) + response = await client.get_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +@pytest.mark.asyncio +async def test_get_reference_image_async_from_dict(): + await test_get_reference_image_async(request_type=dict) + + +def test_get_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + call.return_value = product_search_service.ReferenceImage() + client.get_reference_image(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_get_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + await client.get_reference_image(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_get_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_reference_image( + 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_get_reference_image_flattened_error(): + client = ProductSearchClient( + 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.get_reference_image( + product_search_service.GetReferenceImageRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_reference_image( + 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_get_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_reference_image( + product_search_service.GetReferenceImageRequest(), + name='name_value', + ) + + +def test_add_product_to_product_set(transport: str = 'grpc', request_type=product_search_service.AddProductToProductSetRequest): + client = ProductSearchClient( + 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.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.add_product_to_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_add_product_to_product_set_from_dict(): + test_add_product_to_product_set(request_type=dict) + + +def test_add_product_to_product_set_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 = ProductSearchClient( + 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.add_product_to_product_set), + '__call__') as call: + client.add_product_to_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.AddProductToProductSetRequest): + client = ProductSearchAsyncClient( + 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.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.add_product_to_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_async_from_dict(): + await test_add_product_to_product_set_async(request_type=dict) + + +def test_add_product_to_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.AddProductToProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + call.return_value = None + client.add_product_to_product_set(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_add_product_to_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.AddProductToProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.add_product_to_product_set(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_add_product_to_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_product_to_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +def test_add_product_to_product_set_flattened_error(): + client = ProductSearchClient( + 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.add_product_to_product_set( + product_search_service.AddProductToProductSetRequest(), + name='name_value', + product='product_value', + ) + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_product_to_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.add_product_to_product_set( + product_search_service.AddProductToProductSetRequest(), + name='name_value', + product='product_value', + ) + + +def test_remove_product_from_product_set(transport: str = 'grpc', request_type=product_search_service.RemoveProductFromProductSetRequest): + client = ProductSearchClient( + 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.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.remove_product_from_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_remove_product_from_product_set_from_dict(): + test_remove_product_from_product_set(request_type=dict) + + +def test_remove_product_from_product_set_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 = ProductSearchClient( + 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.remove_product_from_product_set), + '__call__') as call: + client.remove_product_from_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.RemoveProductFromProductSetRequest): + client = ProductSearchAsyncClient( + 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.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.remove_product_from_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_async_from_dict(): + await test_remove_product_from_product_set_async(request_type=dict) + + +def test_remove_product_from_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.RemoveProductFromProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + call.return_value = None + client.remove_product_from_product_set(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_remove_product_from_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.RemoveProductFromProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.remove_product_from_product_set(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_remove_product_from_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.remove_product_from_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +def test_remove_product_from_product_set_flattened_error(): + client = ProductSearchClient( + 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.remove_product_from_product_set( + product_search_service.RemoveProductFromProductSetRequest(), + name='name_value', + product='product_value', + ) + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.remove_product_from_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.remove_product_from_product_set( + product_search_service.RemoveProductFromProductSetRequest(), + name='name_value', + product='product_value', + ) + + +def test_list_products_in_product_set(transport: str = 'grpc', request_type=product_search_service.ListProductsInProductSetRequest): + client = ProductSearchClient( + 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_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products_in_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsInProductSetPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_in_product_set_from_dict(): + test_list_products_in_product_set(request_type=dict) + + +def test_list_products_in_product_set_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 = ProductSearchClient( + 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_products_in_product_set), + '__call__') as call: + client.list_products_in_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsInProductSetRequest): + client = ProductSearchAsyncClient( + 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_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products_in_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsInProductSetAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async_from_dict(): + await test_list_products_in_product_set_async(request_type=dict) + + +def test_list_products_in_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductsInProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + call.return_value = product_search_service.ListProductsInProductSetResponse() + client.list_products_in_product_set(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_list_products_in_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductsInProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) + await client.list_products_in_product_set(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_list_products_in_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products_in_product_set( + 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_list_products_in_product_set_flattened_error(): + client = ProductSearchClient( + 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_products_in_product_set( + product_search_service.ListProductsInProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products_in_product_set( + 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_list_products_in_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_products_in_product_set( + product_search_service.ListProductsInProductSetRequest(), + name='name_value', + ) + + +def test_list_products_in_product_set_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('name', ''), + )), + ) + pager = client.list_products_in_product_set(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.Product) + for i in results) + +def test_list_products_in_product_set_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products_in_product_set(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_products_in_product_set_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products_in_product_set(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, product_search_service.Product) + for i in responses) + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_products_in_product_set(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_import_product_sets(transport: str = 'grpc', request_type=product_search_service.ImportProductSetsRequest): + client = ProductSearchClient( + 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.import_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.import_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_import_product_sets_from_dict(): + test_import_product_sets(request_type=dict) + + +def test_import_product_sets_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 = ProductSearchClient( + 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.import_product_sets), + '__call__') as call: + client.import_product_sets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + +@pytest.mark.asyncio +async def test_import_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ImportProductSetsRequest): + client = ProductSearchAsyncClient( + 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.import_product_sets), + '__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.import_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_import_product_sets_async_from_dict(): + await test_import_product_sets_async(request_type=dict) + + +def test_import_product_sets_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ImportProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.import_product_sets(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_import_product_sets_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ImportProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.import_product_sets(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_import_product_sets_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__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.import_product_sets( + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) + + +def test_import_product_sets_flattened_error(): + client = ProductSearchClient( + 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.import_product_sets( + product_search_service.ImportProductSetsRequest(), + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), + ) + + +@pytest.mark.asyncio +async def test_import_product_sets_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__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.import_product_sets( + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) + + +@pytest.mark.asyncio +async def test_import_product_sets_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.import_product_sets( + product_search_service.ImportProductSetsRequest(), + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductSearchClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductSearchGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, +]) +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 = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductSearchGrpcTransport, + ) + +def test_product_search_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductSearchTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_product_search_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductSearchTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'create_product_set', + 'list_product_sets', + 'get_product_set', + 'update_product_set', + 'delete_product_set', + 'create_product', + 'list_products', + 'get_product', + 'update_product', + 'delete_product', + 'create_reference_image', + 'delete_reference_image', + 'list_reference_images', + 'get_reference_image', + 'add_product_to_product_set', + 'remove_product_from_product_set', + 'list_products_in_product_set', + 'import_product_sets', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_product_search_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) + ProductSearchClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_product_search_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) + ProductSearchClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_product_search_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_product_search_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductSearchGrpcTransport, grpc_helpers), + (transports.ProductSearchGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_product_search_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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_product_search_host_no_port(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_product_search_host_with_port(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_product_search_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductSearchGrpcTransport( + 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_product_search_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductSearchGrpcAsyncIOTransport( + 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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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_product_search_grpc_lro_client(): + client = ProductSearchClient( + 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_product_search_grpc_lro_async_client(): + client = ProductSearchAsyncClient( + 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_product_path(): + project = "squid" + location = "clam" + product = "whelk" + expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + actual = ProductSearchClient.product_path(project, location, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "project": "octopus", + "location": "oyster", + "product": "nudibranch", + } + path = ProductSearchClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_product_path(path) + assert expected == actual + +def test_product_set_path(): + project = "cuttlefish" + location = "mussel" + product_set = "winkle" + expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + actual = ProductSearchClient.product_set_path(project, location, product_set) + assert expected == actual + + +def test_parse_product_set_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "product_set": "abalone", + } + path = ProductSearchClient.product_set_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_product_set_path(path) + assert expected == actual + +def test_reference_image_path(): + project = "squid" + location = "clam" + product = "whelk" + reference_image = "octopus" + expected = "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) + actual = ProductSearchClient.reference_image_path(project, location, product, reference_image) + assert expected == actual + + +def test_parse_reference_image_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "product": "cuttlefish", + "reference_image": "mussel", + } + path = ProductSearchClient.reference_image_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_reference_image_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductSearchClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = ProductSearchClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductSearchClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = ProductSearchClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductSearchClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = ProductSearchClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format(project=project, ) + actual = ProductSearchClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = ProductSearchClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductSearchClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = ProductSearchClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.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.ProductSearchTransport, '_prep_wrapped_messages') as prep: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductSearchTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductSearchClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1p4beta1/.coveragerc b/owl-bot-staging/v1p4beta1/.coveragerc new file mode 100644 index 00000000..75747063 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/vision/__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/v1p4beta1/MANIFEST.in b/owl-bot-staging/v1p4beta1/MANIFEST.in new file mode 100644 index 00000000..47dfa0c1 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/vision *.py +recursive-include google/cloud/vision_v1p4beta1 *.py diff --git a/owl-bot-staging/v1p4beta1/README.rst b/owl-bot-staging/v1p4beta1/README.rst new file mode 100644 index 00000000..39f9ca72 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Vision 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 Vision 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/v1p4beta1/docs/conf.py b/owl-bot-staging/v1p4beta1/docs/conf.py new file mode 100644 index 00000000..6e730bf5 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/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-vision 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-vision" +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-vision-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-vision.tex", + u"google-cloud-vision 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-vision", + u"Google Cloud Vision 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-vision", + u"google-cloud-vision Documentation", + author, + "google-cloud-vision", + "GAPIC library for Google Cloud Vision 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/v1p4beta1/docs/index.rst b/owl-bot-staging/v1p4beta1/docs/index.rst new file mode 100644 index 00000000..ea7e0477 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + vision_v1p4beta1/services + vision_v1p4beta1/types diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst new file mode 100644 index 00000000..28717262 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst @@ -0,0 +1,6 @@ +ImageAnnotator +-------------------------------- + +.. automodule:: google.cloud.vision_v1p4beta1.services.image_annotator + :members: + :inherited-members: diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst new file mode 100644 index 00000000..895f0cba --- /dev/null +++ b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst @@ -0,0 +1,10 @@ +ProductSearch +------------------------------- + +.. automodule:: google.cloud.vision_v1p4beta1.services.product_search + :members: + :inherited-members: + +.. automodule:: google.cloud.vision_v1p4beta1.services.product_search.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst new file mode 100644 index 00000000..2ebd0bbc --- /dev/null +++ b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst @@ -0,0 +1,7 @@ +Services for Google Cloud Vision v1p4beta1 API +============================================== +.. toctree:: + :maxdepth: 2 + + image_annotator + product_search diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst new file mode 100644 index 00000000..a90d1fa2 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Vision v1p4beta1 API +=========================================== + +.. automodule:: google.cloud.vision_v1p4beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py new file mode 100644 index 00000000..038c8422 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py @@ -0,0 +1,201 @@ +# -*- 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.vision_v1p4beta1.services.image_annotator.client import ImageAnnotatorClient +from google.cloud.vision_v1p4beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient +from google.cloud.vision_v1p4beta1.services.product_search.client import ProductSearchClient +from google.cloud.vision_v1p4beta1.services.product_search.async_client import ProductSearchAsyncClient + +from google.cloud.vision_v1p4beta1.types.face import Celebrity +from google.cloud.vision_v1p4beta1.types.face import FaceRecognitionParams +from google.cloud.vision_v1p4beta1.types.face import FaceRecognitionResult +from google.cloud.vision_v1p4beta1.types.geometry import BoundingPoly +from google.cloud.vision_v1p4beta1.types.geometry import NormalizedVertex +from google.cloud.vision_v1p4beta1.types.geometry import Position +from google.cloud.vision_v1p4beta1.types.geometry import Vertex +from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateFileRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateFileResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateImageRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateImageResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncAnnotateFileRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncAnnotateFileResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateFilesRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateFilesResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateImagesRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateImagesResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateFilesRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateFilesResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateImagesRequest +from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateImagesResponse +from google.cloud.vision_v1p4beta1.types.image_annotator import ColorInfo +from google.cloud.vision_v1p4beta1.types.image_annotator import CropHint +from google.cloud.vision_v1p4beta1.types.image_annotator import CropHintsAnnotation +from google.cloud.vision_v1p4beta1.types.image_annotator import CropHintsParams +from google.cloud.vision_v1p4beta1.types.image_annotator import DominantColorsAnnotation +from google.cloud.vision_v1p4beta1.types.image_annotator import EntityAnnotation +from google.cloud.vision_v1p4beta1.types.image_annotator import FaceAnnotation +from google.cloud.vision_v1p4beta1.types.image_annotator import Feature +from google.cloud.vision_v1p4beta1.types.image_annotator import GcsDestination +from google.cloud.vision_v1p4beta1.types.image_annotator import GcsSource +from google.cloud.vision_v1p4beta1.types.image_annotator import Image +from google.cloud.vision_v1p4beta1.types.image_annotator import ImageAnnotationContext +from google.cloud.vision_v1p4beta1.types.image_annotator import ImageContext +from google.cloud.vision_v1p4beta1.types.image_annotator import ImageProperties +from google.cloud.vision_v1p4beta1.types.image_annotator import ImageSource +from google.cloud.vision_v1p4beta1.types.image_annotator import InputConfig +from google.cloud.vision_v1p4beta1.types.image_annotator import LatLongRect +from google.cloud.vision_v1p4beta1.types.image_annotator import LocalizedObjectAnnotation +from google.cloud.vision_v1p4beta1.types.image_annotator import LocationInfo +from google.cloud.vision_v1p4beta1.types.image_annotator import OperationMetadata +from google.cloud.vision_v1p4beta1.types.image_annotator import OutputConfig +from google.cloud.vision_v1p4beta1.types.image_annotator import Property +from google.cloud.vision_v1p4beta1.types.image_annotator import SafeSearchAnnotation +from google.cloud.vision_v1p4beta1.types.image_annotator import TextDetectionParams +from google.cloud.vision_v1p4beta1.types.image_annotator import WebDetectionParams +from google.cloud.vision_v1p4beta1.types.image_annotator import Likelihood +from google.cloud.vision_v1p4beta1.types.product_search import ProductSearchParams +from google.cloud.vision_v1p4beta1.types.product_search import ProductSearchResults +from google.cloud.vision_v1p4beta1.types.product_search_service import AddProductToProductSetRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import BatchOperationMetadata +from google.cloud.vision_v1p4beta1.types.product_search_service import CreateProductRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import CreateProductSetRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import CreateReferenceImageRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import DeleteProductRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import DeleteProductSetRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import DeleteReferenceImageRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import GetProductRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import GetProductSetRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import GetReferenceImageRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsGcsSource +from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsInputConfig +from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsResponse +from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductSetsRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductSetsResponse +from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsInProductSetRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsInProductSetResponse +from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsResponse +from google.cloud.vision_v1p4beta1.types.product_search_service import ListReferenceImagesRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ListReferenceImagesResponse +from google.cloud.vision_v1p4beta1.types.product_search_service import Product +from google.cloud.vision_v1p4beta1.types.product_search_service import ProductSet +from google.cloud.vision_v1p4beta1.types.product_search_service import ProductSetPurgeConfig +from google.cloud.vision_v1p4beta1.types.product_search_service import PurgeProductsRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import ReferenceImage +from google.cloud.vision_v1p4beta1.types.product_search_service import RemoveProductFromProductSetRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import UpdateProductRequest +from google.cloud.vision_v1p4beta1.types.product_search_service import UpdateProductSetRequest +from google.cloud.vision_v1p4beta1.types.text_annotation import Block +from google.cloud.vision_v1p4beta1.types.text_annotation import Page +from google.cloud.vision_v1p4beta1.types.text_annotation import Paragraph +from google.cloud.vision_v1p4beta1.types.text_annotation import Symbol +from google.cloud.vision_v1p4beta1.types.text_annotation import TextAnnotation +from google.cloud.vision_v1p4beta1.types.text_annotation import Word +from google.cloud.vision_v1p4beta1.types.web_detection import WebDetection + +__all__ = ('ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', + 'ProductSearchClient', + 'ProductSearchAsyncClient', + 'Celebrity', + 'FaceRecognitionParams', + 'FaceRecognitionResult', + 'BoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileRequest', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'AsyncBatchAnnotateImagesRequest', + 'AsyncBatchAnnotateImagesResponse', + 'BatchAnnotateFilesRequest', + 'BatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocalizedObjectAnnotation', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'ProductSearchParams', + 'ProductSearchResults', + 'AddProductToProductSetRequest', + 'BatchOperationMetadata', + 'CreateProductRequest', + 'CreateProductSetRequest', + 'CreateReferenceImageRequest', + 'DeleteProductRequest', + 'DeleteProductSetRequest', + 'DeleteReferenceImageRequest', + 'GetProductRequest', + 'GetProductSetRequest', + 'GetReferenceImageRequest', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ListProductsRequest', + 'ListProductsResponse', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'Product', + 'ProductSet', + 'ProductSetPurgeConfig', + 'PurgeProductsRequest', + 'ReferenceImage', + 'RemoveProductFromProductSetRequest', + 'UpdateProductRequest', + 'UpdateProductSetRequest', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py new file mode 100644 index 00000000..2464becd --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py @@ -0,0 +1,202 @@ +# -*- 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.image_annotator import ImageAnnotatorClient +from .services.image_annotator import ImageAnnotatorAsyncClient +from .services.product_search import ProductSearchClient +from .services.product_search import ProductSearchAsyncClient + +from .types.face import Celebrity +from .types.face import FaceRecognitionParams +from .types.face import FaceRecognitionResult +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Position +from .types.geometry import Vertex +from .types.image_annotator import AnnotateFileRequest +from .types.image_annotator import AnnotateFileResponse +from .types.image_annotator import AnnotateImageRequest +from .types.image_annotator import AnnotateImageResponse +from .types.image_annotator import AsyncAnnotateFileRequest +from .types.image_annotator import AsyncAnnotateFileResponse +from .types.image_annotator import AsyncBatchAnnotateFilesRequest +from .types.image_annotator import AsyncBatchAnnotateFilesResponse +from .types.image_annotator import AsyncBatchAnnotateImagesRequest +from .types.image_annotator import AsyncBatchAnnotateImagesResponse +from .types.image_annotator import BatchAnnotateFilesRequest +from .types.image_annotator import BatchAnnotateFilesResponse +from .types.image_annotator import BatchAnnotateImagesRequest +from .types.image_annotator import BatchAnnotateImagesResponse +from .types.image_annotator import ColorInfo +from .types.image_annotator import CropHint +from .types.image_annotator import CropHintsAnnotation +from .types.image_annotator import CropHintsParams +from .types.image_annotator import DominantColorsAnnotation +from .types.image_annotator import EntityAnnotation +from .types.image_annotator import FaceAnnotation +from .types.image_annotator import Feature +from .types.image_annotator import GcsDestination +from .types.image_annotator import GcsSource +from .types.image_annotator import Image +from .types.image_annotator import ImageAnnotationContext +from .types.image_annotator import ImageContext +from .types.image_annotator import ImageProperties +from .types.image_annotator import ImageSource +from .types.image_annotator import InputConfig +from .types.image_annotator import LatLongRect +from .types.image_annotator import LocalizedObjectAnnotation +from .types.image_annotator import LocationInfo +from .types.image_annotator import OperationMetadata +from .types.image_annotator import OutputConfig +from .types.image_annotator import Property +from .types.image_annotator import SafeSearchAnnotation +from .types.image_annotator import TextDetectionParams +from .types.image_annotator import WebDetectionParams +from .types.image_annotator import Likelihood +from .types.product_search import ProductSearchParams +from .types.product_search import ProductSearchResults +from .types.product_search_service import AddProductToProductSetRequest +from .types.product_search_service import BatchOperationMetadata +from .types.product_search_service import CreateProductRequest +from .types.product_search_service import CreateProductSetRequest +from .types.product_search_service import CreateReferenceImageRequest +from .types.product_search_service import DeleteProductRequest +from .types.product_search_service import DeleteProductSetRequest +from .types.product_search_service import DeleteReferenceImageRequest +from .types.product_search_service import GetProductRequest +from .types.product_search_service import GetProductSetRequest +from .types.product_search_service import GetReferenceImageRequest +from .types.product_search_service import ImportProductSetsGcsSource +from .types.product_search_service import ImportProductSetsInputConfig +from .types.product_search_service import ImportProductSetsRequest +from .types.product_search_service import ImportProductSetsResponse +from .types.product_search_service import ListProductSetsRequest +from .types.product_search_service import ListProductSetsResponse +from .types.product_search_service import ListProductsInProductSetRequest +from .types.product_search_service import ListProductsInProductSetResponse +from .types.product_search_service import ListProductsRequest +from .types.product_search_service import ListProductsResponse +from .types.product_search_service import ListReferenceImagesRequest +from .types.product_search_service import ListReferenceImagesResponse +from .types.product_search_service import Product +from .types.product_search_service import ProductSet +from .types.product_search_service import ProductSetPurgeConfig +from .types.product_search_service import PurgeProductsRequest +from .types.product_search_service import ReferenceImage +from .types.product_search_service import RemoveProductFromProductSetRequest +from .types.product_search_service import UpdateProductRequest +from .types.product_search_service import UpdateProductSetRequest +from .types.text_annotation import Block +from .types.text_annotation import Page +from .types.text_annotation import Paragraph +from .types.text_annotation import Symbol +from .types.text_annotation import TextAnnotation +from .types.text_annotation import Word +from .types.web_detection import WebDetection + +__all__ = ( + 'ImageAnnotatorAsyncClient', + 'ProductSearchAsyncClient', +'AddProductToProductSetRequest', +'AnnotateFileRequest', +'AnnotateFileResponse', +'AnnotateImageRequest', +'AnnotateImageResponse', +'AsyncAnnotateFileRequest', +'AsyncAnnotateFileResponse', +'AsyncBatchAnnotateFilesRequest', +'AsyncBatchAnnotateFilesResponse', +'AsyncBatchAnnotateImagesRequest', +'AsyncBatchAnnotateImagesResponse', +'BatchAnnotateFilesRequest', +'BatchAnnotateFilesResponse', +'BatchAnnotateImagesRequest', +'BatchAnnotateImagesResponse', +'BatchOperationMetadata', +'Block', +'BoundingPoly', +'Celebrity', +'ColorInfo', +'CreateProductRequest', +'CreateProductSetRequest', +'CreateReferenceImageRequest', +'CropHint', +'CropHintsAnnotation', +'CropHintsParams', +'DeleteProductRequest', +'DeleteProductSetRequest', +'DeleteReferenceImageRequest', +'DominantColorsAnnotation', +'EntityAnnotation', +'FaceAnnotation', +'FaceRecognitionParams', +'FaceRecognitionResult', +'Feature', +'GcsDestination', +'GcsSource', +'GetProductRequest', +'GetProductSetRequest', +'GetReferenceImageRequest', +'Image', +'ImageAnnotationContext', +'ImageAnnotatorClient', +'ImageContext', +'ImageProperties', +'ImageSource', +'ImportProductSetsGcsSource', +'ImportProductSetsInputConfig', +'ImportProductSetsRequest', +'ImportProductSetsResponse', +'InputConfig', +'LatLongRect', +'Likelihood', +'ListProductSetsRequest', +'ListProductSetsResponse', +'ListProductsInProductSetRequest', +'ListProductsInProductSetResponse', +'ListProductsRequest', +'ListProductsResponse', +'ListReferenceImagesRequest', +'ListReferenceImagesResponse', +'LocalizedObjectAnnotation', +'LocationInfo', +'NormalizedVertex', +'OperationMetadata', +'OutputConfig', +'Page', +'Paragraph', +'Position', +'Product', +'ProductSearchClient', +'ProductSearchParams', +'ProductSearchResults', +'ProductSet', +'ProductSetPurgeConfig', +'Property', +'PurgeProductsRequest', +'ReferenceImage', +'RemoveProductFromProductSetRequest', +'SafeSearchAnnotation', +'Symbol', +'TextAnnotation', +'TextDetectionParams', +'UpdateProductRequest', +'UpdateProductSetRequest', +'Vertex', +'WebDetection', +'WebDetectionParams', +'Word', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json new file mode 100644 index 00000000..bc41c344 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json @@ -0,0 +1,267 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.vision_v1p4beta1", + "protoPackage": "google.cloud.vision.v1p4beta1", + "schema": "1.0", + "services": { + "ImageAnnotator": { + "clients": { + "grpc": { + "libraryClient": "ImageAnnotatorClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "AsyncBatchAnnotateImages": { + "methods": [ + "async_batch_annotate_images" + ] + }, + "BatchAnnotateFiles": { + "methods": [ + "batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ImageAnnotatorAsyncClient", + "rpcs": { + "AsyncBatchAnnotateFiles": { + "methods": [ + "async_batch_annotate_files" + ] + }, + "AsyncBatchAnnotateImages": { + "methods": [ + "async_batch_annotate_images" + ] + }, + "BatchAnnotateFiles": { + "methods": [ + "batch_annotate_files" + ] + }, + "BatchAnnotateImages": { + "methods": [ + "batch_annotate_images" + ] + } + } + } + } + }, + "ProductSearch": { + "clients": { + "grpc": { + "libraryClient": "ProductSearchClient", + "rpcs": { + "AddProductToProductSet": { + "methods": [ + "add_product_to_product_set" + ] + }, + "CreateProduct": { + "methods": [ + "create_product" + ] + }, + "CreateProductSet": { + "methods": [ + "create_product_set" + ] + }, + "CreateReferenceImage": { + "methods": [ + "create_reference_image" + ] + }, + "DeleteProduct": { + "methods": [ + "delete_product" + ] + }, + "DeleteProductSet": { + "methods": [ + "delete_product_set" + ] + }, + "DeleteReferenceImage": { + "methods": [ + "delete_reference_image" + ] + }, + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "GetProductSet": { + "methods": [ + "get_product_set" + ] + }, + "GetReferenceImage": { + "methods": [ + "get_reference_image" + ] + }, + "ImportProductSets": { + "methods": [ + "import_product_sets" + ] + }, + "ListProductSets": { + "methods": [ + "list_product_sets" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + }, + "ListProductsInProductSet": { + "methods": [ + "list_products_in_product_set" + ] + }, + "ListReferenceImages": { + "methods": [ + "list_reference_images" + ] + }, + "PurgeProducts": { + "methods": [ + "purge_products" + ] + }, + "RemoveProductFromProductSet": { + "methods": [ + "remove_product_from_product_set" + ] + }, + "UpdateProduct": { + "methods": [ + "update_product" + ] + }, + "UpdateProductSet": { + "methods": [ + "update_product_set" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductSearchAsyncClient", + "rpcs": { + "AddProductToProductSet": { + "methods": [ + "add_product_to_product_set" + ] + }, + "CreateProduct": { + "methods": [ + "create_product" + ] + }, + "CreateProductSet": { + "methods": [ + "create_product_set" + ] + }, + "CreateReferenceImage": { + "methods": [ + "create_reference_image" + ] + }, + "DeleteProduct": { + "methods": [ + "delete_product" + ] + }, + "DeleteProductSet": { + "methods": [ + "delete_product_set" + ] + }, + "DeleteReferenceImage": { + "methods": [ + "delete_reference_image" + ] + }, + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "GetProductSet": { + "methods": [ + "get_product_set" + ] + }, + "GetReferenceImage": { + "methods": [ + "get_reference_image" + ] + }, + "ImportProductSets": { + "methods": [ + "import_product_sets" + ] + }, + "ListProductSets": { + "methods": [ + "list_product_sets" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + }, + "ListProductsInProductSet": { + "methods": [ + "list_products_in_product_set" + ] + }, + "ListReferenceImages": { + "methods": [ + "list_reference_images" + ] + }, + "PurgeProducts": { + "methods": [ + "purge_products" + ] + }, + "RemoveProductFromProductSet": { + "methods": [ + "remove_product_from_product_set" + ] + }, + "UpdateProduct": { + "methods": [ + "update_product" + ] + }, + "UpdateProductSet": { + "methods": [ + "update_product_set" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed new file mode 100644 index 00000000..8cb07491 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/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/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py new file mode 100644 index 00000000..3cbfa2fa --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__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 ImageAnnotatorClient +from .async_client import ImageAnnotatorAsyncClient + +__all__ = ( + 'ImageAnnotatorClient', + 'ImageAnnotatorAsyncClient', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py new file mode 100644 index 00000000..1b40908d --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py @@ -0,0 +1,517 @@ +# -*- 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.vision_v1p4beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport +from .client import ImageAnnotatorClient + + +class ImageAnnotatorAsyncClient: + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + _client: ImageAnnotatorClient + + DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT + + product_path = staticmethod(ImageAnnotatorClient.product_path) + parse_product_path = staticmethod(ImageAnnotatorClient.parse_product_path) + product_set_path = staticmethod(ImageAnnotatorClient.product_set_path) + parse_product_set_path = staticmethod(ImageAnnotatorClient.parse_product_set_path) + common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) + parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) + common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) + parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) + common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) + parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) + common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) + parse_common_location_path = staticmethod(ImageAnnotatorClient.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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: + ImageAnnotatorAsyncClient: The constructed client. + """ + return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def batch_annotate_images(self, + request: image_annotator.BatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest`): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1p4beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def batch_annotate_files(self, + request: image_annotator.BatchAnnotateFilesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateFilesResponse: + r"""Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest`): + The request object. A list of requests to annotate files + using the BatchAnnotateFiles API. + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]`): + Required. The list of file annotation + requests. Right now we support only one + AnnotateFileRequest in + BatchAnnotateFilesRequest. + + 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.cloud.vision_v1p4beta1.types.BatchAnnotateFilesResponse: + A list of file annotation responses. + """ + # 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 = image_annotator.BatchAnnotateFilesRequest(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_annotate_files, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def async_batch_annotate_images(self, + request: image_annotator.AsyncBatchAnnotateImagesRequest = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + output_config: image_annotator.OutputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest`): + The request object. Request for async image annotation + for a list of images. + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): + Required. Individual image annotation + requests for this batch. + + This corresponds to the ``requests`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (:class:`google.cloud.vision_v1p4beta1.types.OutputConfig`): + Required. The desired output location + and metadata (e.g. format). + + This corresponds to the ``output_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.vision_v1p4beta1.types.AsyncBatchAnnotateImagesResponse` + Response to an async batch image annotation request. + + """ + # 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, output_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 = image_annotator.AsyncBatchAnnotateImagesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if output_config is not None: + request.output_config = output_config + 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.async_batch_annotate_images, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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, + image_annotator.AsyncBatchAnnotateImagesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + async def async_batch_annotate_files(self, + request: image_annotator.AsyncBatchAnnotateFilesRequest = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest`): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]`): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1p4beta1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorAsyncClient", +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py new file mode 100644 index 00000000..0b78b6a3 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py @@ -0,0 +1,703 @@ +# -*- 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 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.vision_v1p4beta1.types import image_annotator +from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ImageAnnotatorGrpcTransport +from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +class ImageAnnotatorClientMeta(type): + """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] + _transport_registry["grpc"] = ImageAnnotatorGrpcTransport + _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ImageAnnotatorTransport]: + """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): + """Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + """ + + @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 = "vision.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: + ImageAnnotatorClient: 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: + ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: + """Returns the transport used by the client instance. + + Returns: + ImageAnnotatorTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(project: str,location: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_set_path(project: str,location: str,product_set: str,) -> str: + """Returns a fully-qualified product_set string.""" + return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + + @staticmethod + def parse_product_set_path(path: str) -> Dict[str,str]: + """Parses a product_set path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?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, ImageAnnotatorTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): + # transport is a ImageAnnotatorTransport 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, + always_use_jwt_access=True, + ) + + def batch_annotate_images(self, + request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateImagesResponse: + r"""Run image detection and annotation for a batch of + images. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest, dict]): + The request object. Multiple image annotation requests + are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + + 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.cloud.vision_v1p4beta1.types.BatchAnnotateImagesResponse: + Response to a batch image annotation + request. + + """ + # 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 image_annotator.BatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): + request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def batch_annotate_files(self, + request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> image_annotator.BatchAnnotateFilesResponse: + r"""Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest, dict]): + The request object. A list of requests to annotate files + using the BatchAnnotateFiles API. + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]): + Required. The list of file annotation + requests. Right now we support only one + AnnotateFileRequest in + BatchAnnotateFilesRequest. + + 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.cloud.vision_v1p4beta1.types.BatchAnnotateFilesResponse: + A list of file annotation responses. + """ + # 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 image_annotator.BatchAnnotateFilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.BatchAnnotateFilesRequest): + request = image_annotator.BatchAnnotateFilesRequest(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_annotate_files] + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def async_batch_annotate_images(self, + request: Union[image_annotator.AsyncBatchAnnotateImagesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AnnotateImageRequest] = None, + output_config: image_annotator.OutputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest, dict]): + The request object. Request for async image annotation + for a list of images. + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + + This corresponds to the ``requests`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): + Required. The desired output location + and metadata (e.g. format). + + This corresponds to the ``output_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.vision_v1p4beta1.types.AsyncBatchAnnotateImagesResponse` + Response to an async batch image annotation request. + + """ + # 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, output_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 image_annotator.AsyncBatchAnnotateImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.AsyncBatchAnnotateImagesRequest): + request = image_annotator.AsyncBatchAnnotateImagesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if requests is not None: + request.requests = requests + if output_config is not None: + request.output_config = output_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.async_batch_annotate_images] + + # 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, + image_annotator.AsyncBatchAnnotateImagesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + def async_batch_annotate_files(self, + request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, + *, + requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest, dict]): + The request object. Multiple async file annotation + requests are batched into a single service call. + requests (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]): + Required. Individual async file + annotation requests for this batch. + + 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.vision_v1p4beta1.types.AsyncBatchAnnotateFilesResponse` + Response to an async batch file annotation request. + + """ + # 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 image_annotator.AsyncBatchAnnotateFilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): + request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] + + # 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, + image_annotator.AsyncBatchAnnotateFilesResponse, + metadata_type=image_annotator.OperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ImageAnnotatorClient", +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py new file mode 100644 index 00000000..94f01250 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/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 ImageAnnotatorTransport +from .grpc import ImageAnnotatorGrpcTransport +from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] +_transport_registry['grpc'] = ImageAnnotatorGrpcTransport +_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport + +__all__ = ( + 'ImageAnnotatorTransport', + 'ImageAnnotatorGrpcTransport', + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py new file mode 100644 index 00000000..6c21970e --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py @@ -0,0 +1,247 @@ +# -*- 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.vision_v1p4beta1.types import image_annotator +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-vision', + ).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 ImageAnnotatorTransport(abc.ABC): + """Abstract transport class for ImageAnnotator.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( + self.batch_annotate_images, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.batch_annotate_files: gapic_v1.method.wrap_method( + self.batch_annotate_files, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.async_batch_annotate_images: gapic_v1.method.wrap_method( + self.async_batch_annotate_images, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.async_batch_annotate_files: gapic_v1.method.wrap_method( + self.async_batch_annotate_files, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def batch_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Union[ + image_annotator.BatchAnnotateImagesResponse, + Awaitable[image_annotator.BatchAnnotateImagesResponse] + ]]: + raise NotImplementedError() + + @property + def batch_annotate_files(self) -> Callable[ + [image_annotator.BatchAnnotateFilesRequest], + Union[ + image_annotator.BatchAnnotateFilesResponse, + Awaitable[image_annotator.BatchAnnotateFilesResponse] + ]]: + raise NotImplementedError() + + @property + def async_batch_annotate_images(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateImagesRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ImageAnnotatorTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py new file mode 100644 index 00000000..2aee2f9c --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py @@ -0,0 +1,379 @@ +# -*- 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.vision_v1p4beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO + + +class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): + """gRPC backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + image_annotator.BatchAnnotateImagesResponse]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + ~.BatchAnnotateImagesResponse]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def batch_annotate_files(self) -> Callable[ + [image_annotator.BatchAnnotateFilesRequest], + image_annotator.BatchAnnotateFilesResponse]: + r"""Return a callable for the batch annotate files method over gRPC. + + Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Returns: + Callable[[~.BatchAnnotateFilesRequest], + ~.BatchAnnotateFilesResponse]: + 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_annotate_files' not in self._stubs: + self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateFiles', + request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, + ) + return self._stubs['batch_annotate_files'] + + @property + def async_batch_annotate_images(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateImagesRequest], + operations_pb2.Operation]: + r"""Return a callable for the async batch annotate images method over gRPC. + + Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Returns: + Callable[[~.AsyncBatchAnnotateImagesRequest], + ~.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 'async_batch_annotate_images' not in self._stubs: + self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages', + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + operations_pb2.Operation]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + ~.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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ImageAnnotatorGrpcTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py new file mode 100644 index 00000000..78ba0550 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py @@ -0,0 +1,384 @@ +# -*- 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.vision_v1p4beta1.types import image_annotator +from google.longrunning import operations_pb2 # type: ignore +from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO +from .grpc import ImageAnnotatorGrpcTransport + + +class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): + """gRPC AsyncIO backend transport for ImageAnnotator. + + Service that performs Google Cloud Vision API detection tasks + over client images, such as face, landmark, logo, label, and + text detection. The ImageAnnotator service returns detected + entities from the images. + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ + [image_annotator.BatchAnnotateImagesRequest], + Awaitable[image_annotator.BatchAnnotateImagesResponse]]: + r"""Return a callable for the batch annotate images method over gRPC. + + Run image detection and annotation for a batch of + images. + + Returns: + Callable[[~.BatchAnnotateImagesRequest], + Awaitable[~.BatchAnnotateImagesResponse]]: + 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_annotate_images' not in self._stubs: + self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateImages', + request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, + ) + return self._stubs['batch_annotate_images'] + + @property + def batch_annotate_files(self) -> Callable[ + [image_annotator.BatchAnnotateFilesRequest], + Awaitable[image_annotator.BatchAnnotateFilesResponse]]: + r"""Return a callable for the batch annotate files method over gRPC. + + Service that performs image detection and annotation + for a batch of files. Now only "application/pdf", + "image/tiff" and "image/gif" are supported. + This service will extract at most 5 (customers can + specify which 5 in AnnotateFileRequest.pages) frames + (gif) or pages (pdf or tiff) from each file provided and + perform detection and annotation for each image + extracted. + + Returns: + Callable[[~.BatchAnnotateFilesRequest], + Awaitable[~.BatchAnnotateFilesResponse]]: + 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_annotate_files' not in self._stubs: + self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateFiles', + request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, + response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, + ) + return self._stubs['batch_annotate_files'] + + @property + def async_batch_annotate_images(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateImagesRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the async batch annotate images method over gRPC. + + Run asynchronous image detection and annotation for a list of + images. + + Progress and results can be retrieved through the + ``google.longrunning.Operations`` interface. + ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateImagesResponse`` (results). + + This service will write image annotation outputs to json files + in customer GCS bucket, each json file containing + BatchAnnotateImagesResponse proto. + + Returns: + Callable[[~.AsyncBatchAnnotateImagesRequest], + 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 'async_batch_annotate_images' not in self._stubs: + self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages', + request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_images'] + + @property + def async_batch_annotate_files(self) -> Callable[ + [image_annotator.AsyncBatchAnnotateFilesRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the async batch annotate files method over gRPC. + + Run asynchronous image detection and annotation for a list of + generic files, such as PDF files, which may contain multiple + pages and multiple images per page. Progress and results can be + retrieved through the ``google.longrunning.Operations`` + interface. ``Operation.metadata`` contains ``OperationMetadata`` + (metadata). ``Operation.response`` contains + ``AsyncBatchAnnotateFilesResponse`` (results). + + Returns: + Callable[[~.AsyncBatchAnnotateFilesRequest], + 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 'async_batch_annotate_files' not in self._stubs: + self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles', + request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['async_batch_annotate_files'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ImageAnnotatorGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__init__.py new file mode 100644 index 00000000..cf79a54d --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__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 ProductSearchClient +from .async_client import ProductSearchAsyncClient + +__all__ = ( + 'ProductSearchClient', + 'ProductSearchAsyncClient', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py new file mode 100644 index 00000000..669c9459 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py @@ -0,0 +1,2095 @@ +# -*- 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.vision_v1p4beta1.services.product_search import pagers +from google.cloud.vision_v1p4beta1.types import geometry +from google.cloud.vision_v1p4beta1.types import product_search_service +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport +from .client import ProductSearchClient + + +class ProductSearchAsyncClient: + """Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + """ + + _client: ProductSearchClient + + DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT + + product_path = staticmethod(ProductSearchClient.product_path) + parse_product_path = staticmethod(ProductSearchClient.parse_product_path) + product_set_path = staticmethod(ProductSearchClient.product_set_path) + parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) + reference_image_path = staticmethod(ProductSearchClient.reference_image_path) + parse_reference_image_path = staticmethod(ProductSearchClient.parse_reference_image_path) + common_billing_account_path = staticmethod(ProductSearchClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductSearchClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductSearchClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductSearchClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductSearchClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductSearchClient.parse_common_organization_path) + common_project_path = staticmethod(ProductSearchClient.common_project_path) + parse_common_project_path = staticmethod(ProductSearchClient.parse_common_project_path) + common_location_path = staticmethod(ProductSearchClient.common_location_path) + parse_common_location_path = staticmethod(ProductSearchClient.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: + ProductSearchAsyncClient: The constructed client. + """ + return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, 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: + ProductSearchAsyncClient: The constructed client. + """ + return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductSearchTransport: + """Returns the transport used by the client instance. + + Returns: + ProductSearchTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(ProductSearchClient).get_transport_class, type(ProductSearchClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, ProductSearchTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product search 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, ~.ProductSearchTransport]): 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 = ProductSearchClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def create_product_set(self, + request: product_search_service.CreateProductSetRequest = None, + *, + parent: str = None, + product_set: product_search_service.ProductSet = None, + product_set_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductSetRequest`): + The request object. Request message for the + `CreateProductSet` method. + parent (:class:`str`): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): + Required. The ProductSet to create. + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set_id (:class:`str`): + A user-supplied resource id for this ProductSet. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_set_id`` 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.vision_v1p4beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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, product_set, product_set_id]) + 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 = product_search_service.CreateProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product_set is not None: + request.product_set = product_set + if product_set_id is not None: + request.product_set_id = product_set_id + + # 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_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def list_product_sets(self, + request: product_search_service.ListProductSetsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductSetsAsyncPager: + r"""Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.ListProductSetsRequest`): + The request object. Request message for the + `ListProductSets` method. + parent (:class:`str`): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.vision_v1p4beta1.services.product_search.pagers.ListProductSetsAsyncPager: + Response message for the ListProductSets method. + + 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 = product_search_service.ListProductSetsRequest(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_product_sets, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductSetsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_product_set(self, + request: product_search_service.GetProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.GetProductSetRequest`): + The request object. Request message for the + `GetProductSet` method. + name (:class:`str`): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p4beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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 = product_search_service.GetProductSetRequest(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.get_product_set, + 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=600.0, + ), + default_timeout=600.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 update_product_set(self, + request: product_search_service.UpdateProductSetRequest = None, + *, + product_set: product_search_service.ProductSet = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest`): + The request object. Request message for the + `UpdateProductSet` method. + product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): + Required. The ProductSet resource + which replaces the one on the server. + + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask path is ``display_name``. + + This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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([product_set, update_mask]) + 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 = product_search_service.UpdateProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_set is not None: + request.product_set = product_set + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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(( + ("product_set.name", request.product_set.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product_set(self, + request: product_search_service.DeleteProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest`): + The request object. Request message for the + `DeleteProductSet` method. + name (:class:`str`): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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. + """ + # 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 = product_search_service.DeleteProductSetRequest(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_product_set, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_product(self, + request: product_search_service.CreateProductRequest = None, + *, + parent: str = None, + product: product_search_service.Product = None, + product_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductRequest`): + The request object. Request message for the + `CreateProduct` method. + parent (:class:`str`): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`google.cloud.vision_v1p4beta1.types.Product`): + Required. The product to create. + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_id (:class:`str`): + A user-supplied resource id for this Product. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_id`` 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.vision_v1p4beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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, product, product_id]) + 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 = product_search_service.CreateProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product is not None: + request.product = product + if product_id is not None: + request.product_id = product_id + + # 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_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def list_products(self, + request: product_search_service.ListProductsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsAsyncPager: + r"""Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsRequest`): + The request object. Request message for the + `ListProducts` method. + parent (:class:`str`): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + + 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.vision_v1p4beta1.services.product_search.pagers.ListProductsAsyncPager: + Response message for the ListProducts method. + + 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 = product_search_service.ListProductsRequest(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_products, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_product(self, + request: product_search_service.GetProductRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.GetProductRequest`): + The request object. Request message for the `GetProduct` + method. + name (:class:`str`): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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.vision_v1p4beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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 = product_search_service.GetProductRequest(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.get_product, + 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=600.0, + ), + default_timeout=600.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 update_product(self, + request: product_search_service.UpdateProductRequest = None, + *, + product: product_search_service.Product = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductRequest`): + The request object. Request message for the + `UpdateProduct` method. + product (:class:`google.cloud.vision_v1p4beta1.types.Product`): + Required. The Product resource which + replaces the one on the server. + product.name is immutable. + + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask paths include ``product_labels``, ``display_name``, + and ``description``. + + This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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([product, update_mask]) + 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 = product_search_service.UpdateProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product is not None: + request.product = product + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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(( + ("product.name", request.product.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product(self, + request: product_search_service.DeleteProductRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductRequest`): + The request object. Request message for the + `DeleteProduct` method. + name (:class:`str`): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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. + """ + # 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 = product_search_service.DeleteProductRequest(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_product, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_reference_image(self, + request: product_search_service.CreateReferenceImageRequest = None, + *, + parent: str = None, + reference_image: product_search_service.ReferenceImage = None, + reference_image_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest`): + The request object. Request message for the + `CreateReferenceImage` method. + parent (:class:`str`): + Required. Resource name of the product in which to + create the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image (:class:`google.cloud.vision_v1p4beta1.types.ReferenceImage`): + Required. The reference image to + create. If an image ID is specified, it + is ignored. + + This corresponds to the ``reference_image`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image_id (:class:`str`): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value + as the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``reference_image_id`` 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.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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, reference_image, reference_image_id]) + 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 = product_search_service.CreateReferenceImageRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reference_image is not None: + request.reference_image = reference_image + if reference_image_id is not None: + request.reference_image_id = reference_image_id + + # 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_reference_image, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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 + + async def delete_reference_image(self, + request: product_search_service.DeleteReferenceImageRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest`): + The request object. Request message for the + `DeleteReferenceImage` method. + name (:class:`str`): + Required. The resource name of the reference image to + delete. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + + 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. + """ + # 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 = product_search_service.DeleteReferenceImageRequest(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_reference_image, + 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=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_reference_images(self, + request: product_search_service.ListReferenceImagesRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReferenceImagesAsyncPager: + r"""Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest`): + The request object. Request message for the + `ListReferenceImages` method. + parent (:class:`str`): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + 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.vision_v1p4beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: + Response message for the ListReferenceImages method. + + 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 = product_search_service.ListReferenceImagesRequest(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_reference_images, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListReferenceImagesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_reference_image(self, + request: product_search_service.GetReferenceImageRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest`): + The request object. Request message for the + `GetReferenceImage` method. + name (:class:`str`): + Required. The resource name of the ReferenceImage to + get. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + 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.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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 = product_search_service.GetReferenceImageRequest(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.get_reference_image, + 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=600.0, + ), + default_timeout=600.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 add_product_to_product_set(self, + request: product_search_service.AddProductToProductSetRequest = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest`): + The request object. Request message for the + `AddProductToProductSet` method. + name (:class:`str`): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`str`): + Required. The resource name for the Product to be added + to this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 = product_search_service.AddProductToProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_product_to_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def remove_product_from_product_set(self, + request: product_search_service.RemoveProductFromProductSetRequest = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Removes a Product from the specified ProductSet. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest`): + The request object. Request message for the + `RemoveProductFromProductSet` method. + name (:class:`str`): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (:class:`str`): + Required. The resource name for the Product to be + removed from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 = product_search_service.RemoveProductFromProductSetRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.remove_product_from_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_products_in_product_set(self, + request: product_search_service.ListProductsInProductSetRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsInProductSetAsyncPager: + r"""Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest`): + The request object. Request message for the + `ListProductsInProductSet` method. + name (:class:`str`): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p4beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: + Response message for the ListProductsInProductSet + method. + + 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([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 = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set, + 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=600.0, + ), + default_timeout=600.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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsInProductSetAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def import_product_sets(self, + request: product_search_service.ImportProductSetsRequest = None, + *, + parent: str = None, + input_config: product_search_service.ImportProductSetsInputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest`): + The request object. Request message for the + `ImportProductSets` method. + parent (:class:`str`): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_config (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig`): + Required. The input content for the + list of requests. + + This corresponds to the ``input_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.vision_v1p4beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + """ + # 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, input_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 = product_search_service.ImportProductSetsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if input_config is not None: + request.input_config = input_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.import_product_sets, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.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, + product_search_service.ImportProductSetsResponse, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + async def purge_products(self, + request: product_search_service.PurgeProductsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Args: + request (:class:`google.cloud.vision_v1p4beta1.types.PurgeProductsRequest`): + The request object. Request message for the + `PurgeProducts` method. + parent (:class:`str`): + Required. The project and location in which the Products + should be deleted. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.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([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 = product_search_service.PurgeProductsRequest(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.purge_products, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ProductSearchAsyncClient", +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py new file mode 100644 index 00000000..4449ccfd --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py @@ -0,0 +1,2200 @@ +# -*- 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 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.vision_v1p4beta1.services.product_search import pagers +from google.cloud.vision_v1p4beta1.types import geometry +from google.cloud.vision_v1p4beta1.types import product_search_service +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductSearchGrpcTransport +from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport + + +class ProductSearchClientMeta(type): + """Metaclass for the ProductSearch 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[ProductSearchTransport]] + _transport_registry["grpc"] = ProductSearchGrpcTransport + _transport_registry["grpc_asyncio"] = ProductSearchGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[ProductSearchTransport]: + """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 ProductSearchClient(metaclass=ProductSearchClientMeta): + """Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + """ + + @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 = "vision.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: + ProductSearchClient: 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: + ProductSearchClient: 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) -> ProductSearchTransport: + """Returns the transport used by the client instance. + + Returns: + ProductSearchTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(project: str,location: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_set_path(project: str,location: str,product_set: str,) -> str: + """Returns a fully-qualified product_set string.""" + return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + + @staticmethod + def parse_product_set_path(path: str) -> Dict[str,str]: + """Parses a product_set path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def reference_image_path(project: str,location: str,product: str,reference_image: str,) -> str: + """Returns a fully-qualified reference_image string.""" + return "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) + + @staticmethod + def parse_reference_image_path(path: str) -> Dict[str,str]: + """Parses a reference_image path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)/referenceImages/(?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, ProductSearchTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product search 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, ProductSearchTransport]): 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, ProductSearchTransport): + # transport is a ProductSearchTransport 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, + always_use_jwt_access=True, + ) + + def create_product_set(self, + request: Union[product_search_service.CreateProductSetRequest, dict] = None, + *, + parent: str = None, + product_set: product_search_service.ProductSet = None, + product_set_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.CreateProductSetRequest, dict]): + The request object. Request message for the + `CreateProductSet` method. + parent (str): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): + Required. The ProductSet to create. + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_set_id (str): + A user-supplied resource id for this ProductSet. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_set_id`` 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.vision_v1p4beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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, product_set, product_set_id]) + 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 product_search_service.CreateProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateProductSetRequest): + request = product_search_service.CreateProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product_set is not None: + request.product_set = product_set + if product_set_id is not None: + request.product_set_id = product_set_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_product_set] + + # 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_product_sets(self, + request: Union[product_search_service.ListProductSetsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductSetsPager: + r"""Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.ListProductSetsRequest, dict]): + The request object. Request message for the + `ListProductSets` method. + parent (str): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.vision_v1p4beta1.services.product_search.pagers.ListProductSetsPager: + Response message for the ListProductSets method. + + 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 product_search_service.ListProductSetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductSetsRequest): + request = product_search_service.ListProductSetsRequest(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_product_sets] + + # 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.ListProductSetsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_product_set(self, + request: Union[product_search_service.GetProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.GetProductSetRequest, dict]): + The request object. Request message for the + `GetProductSet` method. + name (str): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p4beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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 product_search_service.GetProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetProductSetRequest): + request = product_search_service.GetProductSetRequest(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.get_product_set] + + # 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 update_product_set(self, + request: Union[product_search_service.UpdateProductSetRequest, dict] = None, + *, + product_set: product_search_service.ProductSet = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ProductSet: + r"""Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest, dict]): + The request object. Request message for the + `UpdateProductSet` method. + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): + Required. The ProductSet resource + which replaces the one on the server. + + This corresponds to the ``product_set`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask path is ``display_name``. + + This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.ProductSet: + A ProductSet contains Products. A + ProductSet can contain a maximum of 1 + million reference images. If the limit + is exceeded, periodic indexing will + fail. + + """ + # 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([product_set, update_mask]) + 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 product_search_service.UpdateProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.UpdateProductSetRequest): + request = product_search_service.UpdateProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_set is not None: + request.product_set = product_set + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product_set] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_set.name", request.product_set.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product_set(self, + request: Union[product_search_service.DeleteProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest, dict]): + The request object. Request message for the + `DeleteProductSet` method. + name (str): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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. + """ + # 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 product_search_service.DeleteProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteProductSetRequest): + request = product_search_service.DeleteProductSetRequest(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_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_product(self, + request: Union[product_search_service.CreateProductRequest, dict] = None, + *, + parent: str = None, + product: product_search_service.Product = None, + product_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.CreateProductRequest, dict]): + The request object. Request message for the + `CreateProduct` method. + parent (str): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (google.cloud.vision_v1p4beta1.types.Product): + Required. The product to create. + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product_id (str): + A user-supplied resource id for this Product. If set, + the server will attempt to use this value as the + resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``product_id`` 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.vision_v1p4beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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, product, product_id]) + 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 product_search_service.CreateProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateProductRequest): + request = product_search_service.CreateProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if product is not None: + request.product = product + if product_id is not None: + request.product_id = product_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_product] + + # 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_products(self, + request: Union[product_search_service.ListProductsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsPager: + r"""Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.ListProductsRequest, dict]): + The request object. Request message for the + `ListProducts` method. + parent (str): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + + 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.vision_v1p4beta1.services.product_search.pagers.ListProductsPager: + Response message for the ListProducts method. + + 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 product_search_service.ListProductsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductsRequest): + request = product_search_service.ListProductsRequest(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_products] + + # 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.ListProductsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_product(self, + request: Union[product_search_service.GetProductRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.GetProductRequest, dict]): + The request object. Request message for the `GetProduct` + method. + name (str): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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.vision_v1p4beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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 product_search_service.GetProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetProductRequest): + request = product_search_service.GetProductRequest(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.get_product] + + # 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 update_product(self, + request: Union[product_search_service.UpdateProductRequest, dict] = None, + *, + product: product_search_service.Product = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.Product: + r"""Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductRequest, dict]): + The request object. Request message for the + `UpdateProduct` method. + product (google.cloud.vision_v1p4beta1.types.Product): + Required. The Product resource which + replaces the one on the server. + product.name is immutable. + + This corresponds to the ``product`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that + specifies which fields to update. If update_mask isn't + specified, all mutable fields are to be updated. Valid + mask paths include ``product_labels``, ``display_name``, + and ``description``. + + This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.Product: + A Product contains ReferenceImages. + """ + # 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([product, update_mask]) + 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 product_search_service.UpdateProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.UpdateProductRequest): + request = product_search_service.UpdateProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product is not None: + request.product = product + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product.name", request.product.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product(self, + request: Union[product_search_service.DeleteProductRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductRequest, dict]): + The request object. Request message for the + `DeleteProduct` method. + name (str): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + 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. + """ + # 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 product_search_service.DeleteProductRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteProductRequest): + request = product_search_service.DeleteProductRequest(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_product] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_reference_image(self, + request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, + *, + parent: str = None, + reference_image: product_search_service.ReferenceImage = None, + reference_image_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest, dict]): + The request object. Request message for the + `CreateReferenceImage` method. + parent (str): + Required. Resource name of the product in which to + create the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image (google.cloud.vision_v1p4beta1.types.ReferenceImage): + Required. The reference image to + create. If an image ID is specified, it + is ignored. + + This corresponds to the ``reference_image`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reference_image_id (str): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value + as the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + + This corresponds to the ``reference_image_id`` 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.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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, reference_image, reference_image_id]) + 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 product_search_service.CreateReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.CreateReferenceImageRequest): + request = product_search_service.CreateReferenceImageRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if reference_image is not None: + request.reference_image = reference_image + if reference_image_id is not None: + request.reference_image_id = reference_image_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_reference_image] + + # 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_reference_image(self, + request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest, dict]): + The request object. Request message for the + `DeleteReferenceImage` method. + name (str): + Required. The resource name of the reference image to + delete. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + + 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. + """ + # 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 product_search_service.DeleteReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.DeleteReferenceImageRequest): + request = product_search_service.DeleteReferenceImageRequest(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_reference_image] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_reference_images(self, + request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReferenceImagesPager: + r"""Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest, dict]): + The request object. Request message for the + `ListReferenceImages` method. + parent (str): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + 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.vision_v1p4beta1.services.product_search.pagers.ListReferenceImagesPager: + Response message for the ListReferenceImages method. + + 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 product_search_service.ListReferenceImagesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListReferenceImagesRequest): + request = product_search_service.ListReferenceImagesRequest(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_reference_images] + + # 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.ListReferenceImagesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_reference_image(self, + request: Union[product_search_service.GetReferenceImageRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> product_search_service.ReferenceImage: + r"""Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest, dict]): + The request object. Request message for the + `GetReferenceImage` method. + name (str): + Required. The resource name of the ReferenceImage to + get. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + 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.vision_v1p4beta1.types.ReferenceImage: + A ReferenceImage represents a product image and its associated metadata, + such as bounding boxes. + + """ + # 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 product_search_service.GetReferenceImageRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.GetReferenceImageRequest): + request = product_search_service.GetReferenceImageRequest(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.get_reference_image] + + # 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 add_product_to_product_set(self, + request: Union[product_search_service.AddProductToProductSetRequest, dict] = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest, dict]): + The request object. Request message for the + `AddProductToProductSet` method. + name (str): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (str): + Required. The resource name for the Product to be added + to this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 product_search_service.AddProductToProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.AddProductToProductSetRequest): + request = product_search_service.AddProductToProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_product_to_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def remove_product_from_product_set(self, + request: Union[product_search_service.RemoveProductFromProductSetRequest, dict] = None, + *, + name: str = None, + product: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Removes a Product from the specified ProductSet. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest, dict]): + The request object. Request message for the + `RemoveProductFromProductSet` method. + name (str): + Required. The resource name for the ProductSet to + modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + product (str): + Required. The resource name for the Product to be + removed from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + + This corresponds to the ``product`` 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. + """ + # 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, product]) + 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 product_search_service.RemoveProductFromProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.RemoveProductFromProductSetRequest): + request = product_search_service.RemoveProductFromProductSetRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if product is not None: + request.product = product + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.remove_product_from_product_set] + + # 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_products_in_product_set(self, + request: Union[product_search_service.ListProductsInProductSetRequest, dict] = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProductsInProductSetPager: + r"""Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest, dict]): + The request object. Request message for the + `ListProductsInProductSet` method. + name (str): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + + 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.vision_v1p4beta1.services.product_search.pagers.ListProductsInProductSetPager: + Response message for the ListProductsInProductSet + method. + + 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([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 product_search_service.ListProductsInProductSetRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ListProductsInProductSetRequest): + request = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set] + + # 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListProductsInProductSetPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def import_product_sets(self, + request: Union[product_search_service.ImportProductSetsRequest, dict] = None, + *, + parent: str = None, + input_config: product_search_service.ImportProductSetsInputConfig = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest, dict]): + The request object. Request message for the + `ImportProductSets` method. + parent (str): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + input_config (google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig): + Required. The input content for the + list of requests. + + This corresponds to the ``input_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.vision_v1p4beta1.types.ImportProductSetsResponse` + Response message for the ImportProductSets method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + """ + # 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, input_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 product_search_service.ImportProductSetsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.ImportProductSetsRequest): + request = product_search_service.ImportProductSetsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if input_config is not None: + request.input_config = input_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.import_product_sets] + + # 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, + product_search_service.ImportProductSetsResponse, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + def purge_products(self, + request: Union[product_search_service.PurgeProductsRequest, dict] = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Args: + request (Union[google.cloud.vision_v1p4beta1.types.PurgeProductsRequest, dict]): + The request object. Request message for the + `PurgeProducts` method. + parent (str): + Required. The project and location in which the Products + should be deleted. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + + 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.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([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 product_search_service.PurgeProductsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, product_search_service.PurgeProductsRequest): + request = product_search_service.PurgeProductsRequest(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.purge_products] + + # 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, + empty_pb2.Empty, + metadata_type=product_search_service.BatchOperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-vision", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "ProductSearchClient", +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py new file mode 100644 index 00000000..f4e931a2 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py @@ -0,0 +1,506 @@ +# -*- 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, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator + +from google.cloud.vision_v1p4beta1.types import product_search_service + + +class ListProductSetsPager: + """A pager for iterating through ``list_product_sets`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``product_sets`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProductSets`` requests and continue to iterate + through the ``product_sets`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` + 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[..., product_search_service.ListProductSetsResponse], + request: product_search_service.ListProductSetsRequest, + response: product_search_service.ListProductSetsResponse, + *, + 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.vision_v1p4beta1.types.ListProductSetsRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListProductSetsResponse): + 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 = product_search_service.ListProductSetsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductSetsResponse]: + 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) -> Iterator[product_search_service.ProductSet]: + for page in self.pages: + yield from page.product_sets + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductSetsAsyncPager: + """A pager for iterating through ``list_product_sets`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``product_sets`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProductSets`` requests and continue to iterate + through the ``product_sets`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` + 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[product_search_service.ListProductSetsResponse]], + request: product_search_service.ListProductSetsRequest, + response: product_search_service.ListProductSetsResponse, + *, + 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.vision_v1p4beta1.types.ListProductSetsRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListProductSetsResponse): + 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 = product_search_service.ListProductSetsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductSetsResponse]: + 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) -> AsyncIterator[product_search_service.ProductSet]: + async def async_generator(): + async for page in self.pages: + for response in page.product_sets: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` + 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[..., product_search_service.ListProductsResponse], + request: product_search_service.ListProductsRequest, + response: product_search_service.ListProductsResponse, + *, + 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.vision_v1p4beta1.types.ListProductsRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListProductsResponse): + 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 = product_search_service.ListProductsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductsResponse]: + 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) -> Iterator[product_search_service.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsAsyncPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` + 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[product_search_service.ListProductsResponse]], + request: product_search_service.ListProductsRequest, + response: product_search_service.ListProductsResponse, + *, + 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.vision_v1p4beta1.types.ListProductsRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListProductsResponse): + 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 = product_search_service.ListProductsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductsResponse]: + 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) -> AsyncIterator[product_search_service.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListReferenceImagesPager: + """A pager for iterating through ``list_reference_images`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``reference_images`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListReferenceImages`` requests and continue to iterate + through the ``reference_images`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` + 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[..., product_search_service.ListReferenceImagesResponse], + request: product_search_service.ListReferenceImagesRequest, + response: product_search_service.ListReferenceImagesResponse, + *, + 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.vision_v1p4beta1.types.ListReferenceImagesRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse): + 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 = product_search_service.ListReferenceImagesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListReferenceImagesResponse]: + 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) -> Iterator[product_search_service.ReferenceImage]: + for page in self.pages: + yield from page.reference_images + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListReferenceImagesAsyncPager: + """A pager for iterating through ``list_reference_images`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``reference_images`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListReferenceImages`` requests and continue to iterate + through the ``reference_images`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` + 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[product_search_service.ListReferenceImagesResponse]], + request: product_search_service.ListReferenceImagesRequest, + response: product_search_service.ListReferenceImagesResponse, + *, + 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.vision_v1p4beta1.types.ListReferenceImagesRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse): + 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 = product_search_service.ListReferenceImagesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListReferenceImagesResponse]: + 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) -> AsyncIterator[product_search_service.ReferenceImage]: + async def async_generator(): + async for page in self.pages: + for response in page.reference_images: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsInProductSetPager: + """A pager for iterating through ``list_products_in_product_set`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProductsInProductSet`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` + 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[..., product_search_service.ListProductsInProductSetResponse], + request: product_search_service.ListProductsInProductSetRequest, + response: product_search_service.ListProductsInProductSetResponse, + *, + 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.vision_v1p4beta1.types.ListProductsInProductSetRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse): + 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 = product_search_service.ListProductsInProductSetRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[product_search_service.ListProductsInProductSetResponse]: + 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) -> Iterator[product_search_service.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsInProductSetAsyncPager: + """A pager for iterating through ``list_products_in_product_set`` requests. + + This class thinly wraps an initial + :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProductsInProductSet`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` + 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[product_search_service.ListProductsInProductSetResponse]], + request: product_search_service.ListProductsInProductSetRequest, + response: product_search_service.ListProductsInProductSetResponse, + *, + 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.vision_v1p4beta1.types.ListProductsInProductSetRequest): + The initial request object. + response (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse): + 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 = product_search_service.ListProductsInProductSetRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[product_search_service.ListProductsInProductSetResponse]: + 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) -> AsyncIterator[product_search_service.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + 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/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py new file mode 100644 index 00000000..22b20282 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/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 ProductSearchTransport +from .grpc import ProductSearchGrpcTransport +from .grpc_asyncio import ProductSearchGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductSearchTransport]] +_transport_registry['grpc'] = ProductSearchGrpcTransport +_transport_registry['grpc_asyncio'] = ProductSearchGrpcAsyncIOTransport + +__all__ = ( + 'ProductSearchTransport', + 'ProductSearchGrpcTransport', + 'ProductSearchGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py new file mode 100644 index 00000000..be52431c --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py @@ -0,0 +1,548 @@ +# -*- 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.vision_v1p4beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-vision', + ).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 ProductSearchTransport(abc.ABC): + """Abstract transport class for ProductSearch.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ) + + DEFAULT_HOST: str = 'vision.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 are 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.create_product_set: gapic_v1.method.wrap_method( + self.create_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_product_sets: gapic_v1.method.wrap_method( + self.list_product_sets, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_product_set: gapic_v1.method.wrap_method( + self.get_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.update_product_set: gapic_v1.method.wrap_method( + self.update_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_product_set: gapic_v1.method.wrap_method( + self.delete_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.create_product: gapic_v1.method.wrap_method( + self.create_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_products: gapic_v1.method.wrap_method( + self.list_products, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_product: gapic_v1.method.wrap_method( + self.get_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.update_product: gapic_v1.method.wrap_method( + self.update_product, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_product: gapic_v1.method.wrap_method( + self.delete_product, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.create_reference_image: gapic_v1.method.wrap_method( + self.create_reference_image, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.delete_reference_image: gapic_v1.method.wrap_method( + self.delete_reference_image, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_reference_images: gapic_v1.method.wrap_method( + self.list_reference_images, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.get_reference_image: gapic_v1.method.wrap_method( + self.get_reference_image, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.add_product_to_product_set: gapic_v1.method.wrap_method( + self.add_product_to_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.remove_product_from_product_set: gapic_v1.method.wrap_method( + self.remove_product_from_product_set, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.list_products_in_product_set: gapic_v1.method.wrap_method( + self.list_products_in_product_set, + 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=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.import_product_sets: gapic_v1.method.wrap_method( + self.import_product_sets, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + ), + deadline=600.0, + ), + default_timeout=600.0, + client_info=client_info, + ), + self.purge_products: gapic_v1.method.wrap_method( + self.purge_products, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + Union[ + product_search_service.ListProductSetsResponse, + Awaitable[product_search_service.ListProductSetsResponse] + ]]: + raise NotImplementedError() + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + Union[ + product_search_service.ProductSet, + Awaitable[product_search_service.ProductSet] + ]]: + raise NotImplementedError() + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + Union[ + product_search_service.ListProductsResponse, + Awaitable[product_search_service.ListProductsResponse] + ]]: + raise NotImplementedError() + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + Union[ + product_search_service.Product, + Awaitable[product_search_service.Product] + ]]: + raise NotImplementedError() + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + Union[ + product_search_service.ReferenceImage, + Awaitable[product_search_service.ReferenceImage] + ]]: + raise NotImplementedError() + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + Union[ + product_search_service.ListReferenceImagesResponse, + Awaitable[product_search_service.ListReferenceImagesResponse] + ]]: + raise NotImplementedError() + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + Union[ + product_search_service.ReferenceImage, + Awaitable[product_search_service.ReferenceImage] + ]]: + raise NotImplementedError() + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + Union[ + product_search_service.ListProductsInProductSetResponse, + Awaitable[product_search_service.ListProductsInProductSetResponse] + ]]: + raise NotImplementedError() + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def purge_products(self) -> Callable[ + [product_search_service.PurgeProductsRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'ProductSearchTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py new file mode 100644 index 00000000..928fa867 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py @@ -0,0 +1,914 @@ +# -*- 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.vision_v1p4beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO + + +class ProductSearchGrpcTransport(ProductSearchTransport): + """gRPC backend transport for ProductSearch. + + Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + + 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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 create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the create product set method over gRPC. + + Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Returns: + Callable[[~.CreateProductSetRequest], + ~.ProductSet]: + 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_product_set' not in self._stubs: + self._stubs['create_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProductSet', + request_serializer=product_search_service.CreateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['create_product_set'] + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + product_search_service.ListProductSetsResponse]: + r"""Return a callable for the list product sets method over gRPC. + + Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Returns: + Callable[[~.ListProductSetsRequest], + ~.ListProductSetsResponse]: + 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_product_sets' not in self._stubs: + self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductSets', + request_serializer=product_search_service.ListProductSetsRequest.serialize, + response_deserializer=product_search_service.ListProductSetsResponse.deserialize, + ) + return self._stubs['list_product_sets'] + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the get product set method over gRPC. + + Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.GetProductSetRequest], + ~.ProductSet]: + 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 'get_product_set' not in self._stubs: + self._stubs['get_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/GetProductSet', + request_serializer=product_search_service.GetProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['get_product_set'] + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + product_search_service.ProductSet]: + r"""Return a callable for the update product set method over gRPC. + + Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Returns: + Callable[[~.UpdateProductSetRequest], + ~.ProductSet]: + 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 'update_product_set' not in self._stubs: + self._stubs['update_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProductSet', + request_serializer=product_search_service.UpdateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['update_product_set'] + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product set method over gRPC. + + Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteProductSetRequest], + ~.Empty]: + 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_product_set' not in self._stubs: + self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProductSet', + request_serializer=product_search_service.DeleteProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_set'] + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + product_search_service.Product]: + r"""Return a callable for the create product method over gRPC. + + Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Returns: + Callable[[~.CreateProductRequest], + ~.Product]: + 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_product' not in self._stubs: + self._stubs['create_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProduct', + request_serializer=product_search_service.CreateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['create_product'] + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + product_search_service.ListProductsResponse]: + r"""Return a callable for the list products method over gRPC. + + Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsRequest], + ~.ListProductsResponse]: + 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_products' not in self._stubs: + self._stubs['list_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListProducts', + request_serializer=product_search_service.ListProductsRequest.serialize, + response_deserializer=product_search_service.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + product_search_service.Product]: + r"""Return a callable for the get product method over gRPC. + + Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Returns: + Callable[[~.GetProductRequest], + ~.Product]: + 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 'get_product' not in self._stubs: + self._stubs['get_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/GetProduct', + request_serializer=product_search_service.GetProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + product_search_service.Product]: + r"""Return a callable for the update product method over gRPC. + + Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Returns: + Callable[[~.UpdateProductRequest], + ~.Product]: + 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 'update_product' not in self._stubs: + self._stubs['update_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProduct', + request_serializer=product_search_service.UpdateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['update_product'] + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product method over gRPC. + + Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Returns: + Callable[[~.DeleteProductRequest], + ~.Empty]: + 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_product' not in self._stubs: + self._stubs['delete_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProduct', + request_serializer=product_search_service.DeleteProductRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product'] + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + product_search_service.ReferenceImage]: + r"""Return a callable for the create reference image method over gRPC. + + Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Returns: + Callable[[~.CreateReferenceImageRequest], + ~.ReferenceImage]: + 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_reference_image' not in self._stubs: + self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/CreateReferenceImage', + request_serializer=product_search_service.CreateReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['create_reference_image'] + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete reference image method over gRPC. + + Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteReferenceImageRequest], + ~.Empty]: + 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_reference_image' not in self._stubs: + self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteReferenceImage', + request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_reference_image'] + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + product_search_service.ListReferenceImagesResponse]: + r"""Return a callable for the list reference images method over gRPC. + + Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Returns: + Callable[[~.ListReferenceImagesRequest], + ~.ListReferenceImagesResponse]: + 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_reference_images' not in self._stubs: + self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListReferenceImages', + request_serializer=product_search_service.ListReferenceImagesRequest.serialize, + response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, + ) + return self._stubs['list_reference_images'] + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + product_search_service.ReferenceImage]: + r"""Return a callable for the get reference image method over gRPC. + + Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Returns: + Callable[[~.GetReferenceImageRequest], + ~.ReferenceImage]: + 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 'get_reference_image' not in self._stubs: + self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/GetReferenceImage', + request_serializer=product_search_service.GetReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['get_reference_image'] + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the add product to product set method over gRPC. + + Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Returns: + Callable[[~.AddProductToProductSetRequest], + ~.Empty]: + 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 'add_product_to_product_set' not in self._stubs: + self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet', + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['add_product_to_product_set'] + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + empty_pb2.Empty]: + r"""Return a callable for the remove product from product + set method over gRPC. + + Removes a Product from the specified ProductSet. + + Returns: + Callable[[~.RemoveProductFromProductSetRequest], + ~.Empty]: + 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 'remove_product_from_product_set' not in self._stubs: + self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet', + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['remove_product_from_product_set'] + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + product_search_service.ListProductsInProductSetResponse]: + r"""Return a callable for the list products in product set method over gRPC. + + Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsInProductSetRequest], + ~.ListProductsInProductSetResponse]: + 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_products_in_product_set' not in self._stubs: + self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet', + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) + return self._stubs['list_products_in_product_set'] + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + operations_pb2.Operation]: + r"""Return a callable for the import product sets method over gRPC. + + Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Returns: + Callable[[~.ImportProductSetsRequest], + ~.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 'import_product_sets' not in self._stubs: + self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ImportProductSets', + request_serializer=product_search_service.ImportProductSetsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['import_product_sets'] + + @property + def purge_products(self) -> Callable[ + [product_search_service.PurgeProductsRequest], + operations_pb2.Operation]: + r"""Return a callable for the purge products method over gRPC. + + Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Returns: + Callable[[~.PurgeProductsRequest], + ~.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 'purge_products' not in self._stubs: + self._stubs['purge_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/PurgeProducts', + request_serializer=product_search_service.PurgeProductsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['purge_products'] + + def close(self): + self.grpc_channel.close() + +__all__ = ( + 'ProductSearchGrpcTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py new file mode 100644 index 00000000..0778fe9b --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py @@ -0,0 +1,919 @@ +# -*- 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.vision_v1p4beta1.types import product_search_service +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductSearchGrpcTransport + + +class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): + """gRPC AsyncIO backend transport for ProductSearch. + + Manages Products and ProductSets of reference images for use in + product search. It uses the following resource model: + + - The API has a collection of + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, + named ``projects/*/locations/*/productSets/*``, which acts as a + way to put different products into groups to limit + identification. + + In parallel, + + - The API has a collection of + [Product][google.cloud.vision.v1p4beta1.Product] resources, named + ``projects/*/locations/*/products/*`` + + - Each [Product][google.cloud.vision.v1p4beta1.Product] has a + collection of + [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] + resources, named + ``projects/*/locations/*/products/*/referenceImages/*`` + + 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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 create_product_set(self) -> Callable[ + [product_search_service.CreateProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the create product set method over gRPC. + + Creates and returns a new ProductSet resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing, or is + longer than 4096 characters. + + Returns: + Callable[[~.CreateProductSetRequest], + Awaitable[~.ProductSet]]: + 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_product_set' not in self._stubs: + self._stubs['create_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProductSet', + request_serializer=product_search_service.CreateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['create_product_set'] + + @property + def list_product_sets(self) -> Callable[ + [product_search_service.ListProductSetsRequest], + Awaitable[product_search_service.ListProductSetsResponse]]: + r"""Return a callable for the list product sets method over gRPC. + + Lists ProductSets in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100, or + less than 1. + + Returns: + Callable[[~.ListProductSetsRequest], + Awaitable[~.ListProductSetsResponse]]: + 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_product_sets' not in self._stubs: + self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductSets', + request_serializer=product_search_service.ListProductSetsRequest.serialize, + response_deserializer=product_search_service.ListProductSetsResponse.deserialize, + ) + return self._stubs['list_product_sets'] + + @property + def get_product_set(self) -> Callable[ + [product_search_service.GetProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the get product set method over gRPC. + + Gets information associated with a ProductSet. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + + Returns: + Callable[[~.GetProductSetRequest], + Awaitable[~.ProductSet]]: + 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 'get_product_set' not in self._stubs: + self._stubs['get_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/GetProductSet', + request_serializer=product_search_service.GetProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['get_product_set'] + + @property + def update_product_set(self) -> Callable[ + [product_search_service.UpdateProductSetRequest], + Awaitable[product_search_service.ProductSet]]: + r"""Return a callable for the update product set method over gRPC. + + Makes changes to a ProductSet resource. Only display_name can be + updated currently. + + Possible errors: + + - Returns NOT_FOUND if the ProductSet does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but missing from the request or longer than 4096 + characters. + + Returns: + Callable[[~.UpdateProductSetRequest], + Awaitable[~.ProductSet]]: + 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 'update_product_set' not in self._stubs: + self._stubs['update_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProductSet', + request_serializer=product_search_service.UpdateProductSetRequest.serialize, + response_deserializer=product_search_service.ProductSet.deserialize, + ) + return self._stubs['update_product_set'] + + @property + def delete_product_set(self) -> Callable[ + [product_search_service.DeleteProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product set method over gRPC. + + Permanently deletes a ProductSet. Products and + ReferenceImages in the ProductSet are not deleted. + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteProductSetRequest], + Awaitable[~.Empty]]: + 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_product_set' not in self._stubs: + self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProductSet', + request_serializer=product_search_service.DeleteProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_set'] + + @property + def create_product(self) -> Callable[ + [product_search_service.CreateProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the create product method over gRPC. + + Creates and returns a new product resource. + + Possible errors: + + - Returns INVALID_ARGUMENT if display_name is missing or longer + than 4096 characters. + - Returns INVALID_ARGUMENT if description is longer than 4096 + characters. + - Returns INVALID_ARGUMENT if product_category is missing or + invalid. + + Returns: + Callable[[~.CreateProductRequest], + Awaitable[~.Product]]: + 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_product' not in self._stubs: + self._stubs['create_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProduct', + request_serializer=product_search_service.CreateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['create_product'] + + @property + def list_products(self) -> Callable[ + [product_search_service.ListProductsRequest], + Awaitable[product_search_service.ListProductsResponse]]: + r"""Return a callable for the list products method over gRPC. + + Lists products in an unspecified order. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsRequest], + Awaitable[~.ListProductsResponse]]: + 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_products' not in self._stubs: + self._stubs['list_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListProducts', + request_serializer=product_search_service.ListProductsRequest.serialize, + response_deserializer=product_search_service.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + @property + def get_product(self) -> Callable[ + [product_search_service.GetProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the get product method over gRPC. + + Gets information associated with a Product. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + + Returns: + Callable[[~.GetProductRequest], + Awaitable[~.Product]]: + 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 'get_product' not in self._stubs: + self._stubs['get_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/GetProduct', + request_serializer=product_search_service.GetProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def update_product(self) -> Callable[ + [product_search_service.UpdateProductRequest], + Awaitable[product_search_service.Product]]: + r"""Return a callable for the update product method over gRPC. + + Makes changes to a Product resource. Only the ``display_name``, + ``description``, and ``labels`` fields can be updated right now. + + If labels are updated, the change will not be reflected in + queries until the next index time. + + Possible errors: + + - Returns NOT_FOUND if the Product does not exist. + - Returns INVALID_ARGUMENT if display_name is present in + update_mask but is missing from the request or longer than + 4096 characters. + - Returns INVALID_ARGUMENT if description is present in + update_mask but is longer than 4096 characters. + - Returns INVALID_ARGUMENT if product_category is present in + update_mask. + + Returns: + Callable[[~.UpdateProductRequest], + Awaitable[~.Product]]: + 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 'update_product' not in self._stubs: + self._stubs['update_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProduct', + request_serializer=product_search_service.UpdateProductRequest.serialize, + response_deserializer=product_search_service.Product.deserialize, + ) + return self._stubs['update_product'] + + @property + def delete_product(self) -> Callable[ + [product_search_service.DeleteProductRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product method over gRPC. + + Permanently deletes a product and its reference + images. + Metadata of the product and all its images will be + deleted right away, but search queries against + ProductSets containing the product may still work until + all related caches are refreshed. + + Returns: + Callable[[~.DeleteProductRequest], + Awaitable[~.Empty]]: + 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_product' not in self._stubs: + self._stubs['delete_product'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProduct', + request_serializer=product_search_service.DeleteProductRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product'] + + @property + def create_reference_image(self) -> Callable[ + [product_search_service.CreateReferenceImageRequest], + Awaitable[product_search_service.ReferenceImage]]: + r"""Return a callable for the create reference image method over gRPC. + + Creates and returns a new ReferenceImage resource. + + The ``bounding_poly`` field is optional. If ``bounding_poly`` is + not specified, the system will try to detect regions of interest + in the image that are compatible with the product_category on + the parent product. If it is specified, detection is ALWAYS + skipped. The system converts polygons into non-rotated + rectangles. + + Note that the pipeline will resize the image if the image + resolution is too large to process (above 50MP). + + Possible errors: + + - Returns INVALID_ARGUMENT if the image_uri is missing or + longer than 4096 characters. + - Returns INVALID_ARGUMENT if the product does not exist. + - Returns INVALID_ARGUMENT if bounding_poly is not provided, + and nothing compatible with the parent product's + product_category is detected. + - Returns INVALID_ARGUMENT if bounding_poly contains more than + 10 polygons. + + Returns: + Callable[[~.CreateReferenceImageRequest], + Awaitable[~.ReferenceImage]]: + 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_reference_image' not in self._stubs: + self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/CreateReferenceImage', + request_serializer=product_search_service.CreateReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['create_reference_image'] + + @property + def delete_reference_image(self) -> Callable[ + [product_search_service.DeleteReferenceImageRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete reference image method over gRPC. + + Permanently deletes a reference image. + The image metadata will be deleted right away, but + search queries against ProductSets containing the image + may still work until all related caches are refreshed. + + The actual image files are not deleted from Google Cloud + Storage. + + Returns: + Callable[[~.DeleteReferenceImageRequest], + Awaitable[~.Empty]]: + 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_reference_image' not in self._stubs: + self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteReferenceImage', + request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_reference_image'] + + @property + def list_reference_images(self) -> Callable[ + [product_search_service.ListReferenceImagesRequest], + Awaitable[product_search_service.ListReferenceImagesResponse]]: + r"""Return a callable for the list reference images method over gRPC. + + Lists reference images. + + Possible errors: + + - Returns NOT_FOUND if the parent product does not exist. + - Returns INVALID_ARGUMENT if the page_size is greater than + 100, or less than 1. + + Returns: + Callable[[~.ListReferenceImagesRequest], + Awaitable[~.ListReferenceImagesResponse]]: + 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_reference_images' not in self._stubs: + self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListReferenceImages', + request_serializer=product_search_service.ListReferenceImagesRequest.serialize, + response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, + ) + return self._stubs['list_reference_images'] + + @property + def get_reference_image(self) -> Callable[ + [product_search_service.GetReferenceImageRequest], + Awaitable[product_search_service.ReferenceImage]]: + r"""Return a callable for the get reference image method over gRPC. + + Gets information associated with a ReferenceImage. + + Possible errors: + + - Returns NOT_FOUND if the specified image does not exist. + + Returns: + Callable[[~.GetReferenceImageRequest], + Awaitable[~.ReferenceImage]]: + 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 'get_reference_image' not in self._stubs: + self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/GetReferenceImage', + request_serializer=product_search_service.GetReferenceImageRequest.serialize, + response_deserializer=product_search_service.ReferenceImage.deserialize, + ) + return self._stubs['get_reference_image'] + + @property + def add_product_to_product_set(self) -> Callable[ + [product_search_service.AddProductToProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the add product to product set method over gRPC. + + Adds a Product to the specified ProductSet. If the Product is + already present, no change is made. + + One Product can be added to at most 100 ProductSets. + + Possible errors: + + - Returns NOT_FOUND if the Product or the ProductSet doesn't + exist. + + Returns: + Callable[[~.AddProductToProductSetRequest], + Awaitable[~.Empty]]: + 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 'add_product_to_product_set' not in self._stubs: + self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet', + request_serializer=product_search_service.AddProductToProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['add_product_to_product_set'] + + @property + def remove_product_from_product_set(self) -> Callable[ + [product_search_service.RemoveProductFromProductSetRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the remove product from product + set method over gRPC. + + Removes a Product from the specified ProductSet. + + Returns: + Callable[[~.RemoveProductFromProductSetRequest], + Awaitable[~.Empty]]: + 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 'remove_product_from_product_set' not in self._stubs: + self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet', + request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['remove_product_from_product_set'] + + @property + def list_products_in_product_set(self) -> Callable[ + [product_search_service.ListProductsInProductSetRequest], + Awaitable[product_search_service.ListProductsInProductSetResponse]]: + r"""Return a callable for the list products in product set method over gRPC. + + Lists the Products in a ProductSet, in an unspecified order. If + the ProductSet does not exist, the products field of the + response will be empty. + + Possible errors: + + - Returns INVALID_ARGUMENT if page_size is greater than 100 or + less than 1. + + Returns: + Callable[[~.ListProductsInProductSetRequest], + Awaitable[~.ListProductsInProductSetResponse]]: + 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_products_in_product_set' not in self._stubs: + self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet', + request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, + response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, + ) + return self._stubs['list_products_in_product_set'] + + @property + def import_product_sets(self) -> Callable[ + [product_search_service.ImportProductSetsRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the import product sets method over gRPC. + + Asynchronous API that imports a list of reference images to + specified product sets based on a list of image information. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) ``Operation.response`` + contains ``ImportProductSetsResponse``. (results) + + The input source of this method is a csv file on Google Cloud + Storage. For the format of the csv file please see + [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. + + Returns: + Callable[[~.ImportProductSetsRequest], + 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 'import_product_sets' not in self._stubs: + self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/ImportProductSets', + request_serializer=product_search_service.ImportProductSetsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['import_product_sets'] + + @property + def purge_products(self) -> Callable[ + [product_search_service.PurgeProductsRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the purge products method over gRPC. + + Asynchronous API to delete all Products in a ProductSet or all + Products that are in no ProductSet. + + If a Product is a member of the specified ProductSet in addition + to other ProductSets, the Product will still be deleted. + + It is recommended to not delete the specified ProductSet until + after this operation has completed. It is also recommended to + not add any of the Products involved in the batch delete to a + new ProductSet while this operation is running because those + Products may still end up deleted. + + It's not possible to undo the PurgeProducts operation. + Therefore, it is recommended to keep the csv files used in + ImportProductSets (if that was how you originally built the + Product Set) before starting PurgeProducts, in case you need to + re-import the data after deletion. + + If the plan is to purge all of the Products from a ProductSet + and then re-use the empty ProductSet to re-import new Products + into the empty ProductSet, you must wait until the PurgeProducts + operation has finished for that ProductSet. + + The [google.longrunning.Operation][google.longrunning.Operation] + API can be used to keep track of the progress and results of the + request. ``Operation.metadata`` contains + ``BatchOperationMetadata``. (progress) + + Returns: + Callable[[~.PurgeProductsRequest], + 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 'purge_products' not in self._stubs: + self._stubs['purge_products'] = self.grpc_channel.unary_unary( + '/google.cloud.vision.v1p4beta1.ProductSearch/PurgeProducts', + request_serializer=product_search_service.PurgeProductsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['purge_products'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'ProductSearchGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py new file mode 100644 index 00000000..01807949 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py @@ -0,0 +1,206 @@ +# -*- 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 .face import ( + Celebrity, + FaceRecognitionParams, + FaceRecognitionResult, +) +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Position, + Vertex, +) +from .image_annotator import ( + AnnotateFileRequest, + AnnotateFileResponse, + AnnotateImageRequest, + AnnotateImageResponse, + AsyncAnnotateFileRequest, + AsyncAnnotateFileResponse, + AsyncBatchAnnotateFilesRequest, + AsyncBatchAnnotateFilesResponse, + AsyncBatchAnnotateImagesRequest, + AsyncBatchAnnotateImagesResponse, + BatchAnnotateFilesRequest, + BatchAnnotateFilesResponse, + BatchAnnotateImagesRequest, + BatchAnnotateImagesResponse, + ColorInfo, + CropHint, + CropHintsAnnotation, + CropHintsParams, + DominantColorsAnnotation, + EntityAnnotation, + FaceAnnotation, + Feature, + GcsDestination, + GcsSource, + Image, + ImageAnnotationContext, + ImageContext, + ImageProperties, + ImageSource, + InputConfig, + LatLongRect, + LocalizedObjectAnnotation, + LocationInfo, + OperationMetadata, + OutputConfig, + Property, + SafeSearchAnnotation, + TextDetectionParams, + WebDetectionParams, + Likelihood, +) +from .product_search import ( + ProductSearchParams, + ProductSearchResults, +) +from .product_search_service import ( + AddProductToProductSetRequest, + BatchOperationMetadata, + CreateProductRequest, + CreateProductSetRequest, + CreateReferenceImageRequest, + DeleteProductRequest, + DeleteProductSetRequest, + DeleteReferenceImageRequest, + GetProductRequest, + GetProductSetRequest, + GetReferenceImageRequest, + ImportProductSetsGcsSource, + ImportProductSetsInputConfig, + ImportProductSetsRequest, + ImportProductSetsResponse, + ListProductSetsRequest, + ListProductSetsResponse, + ListProductsInProductSetRequest, + ListProductsInProductSetResponse, + ListProductsRequest, + ListProductsResponse, + ListReferenceImagesRequest, + ListReferenceImagesResponse, + Product, + ProductSet, + ProductSetPurgeConfig, + PurgeProductsRequest, + ReferenceImage, + RemoveProductFromProductSetRequest, + UpdateProductRequest, + UpdateProductSetRequest, +) +from .text_annotation import ( + Block, + Page, + Paragraph, + Symbol, + TextAnnotation, + Word, +) +from .web_detection import ( + WebDetection, +) + +__all__ = ( + 'Celebrity', + 'FaceRecognitionParams', + 'FaceRecognitionResult', + 'BoundingPoly', + 'NormalizedVertex', + 'Position', + 'Vertex', + 'AnnotateFileRequest', + 'AnnotateFileResponse', + 'AnnotateImageRequest', + 'AnnotateImageResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'AsyncBatchAnnotateImagesRequest', + 'AsyncBatchAnnotateImagesResponse', + 'BatchAnnotateFilesRequest', + 'BatchAnnotateFilesResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'ColorInfo', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'DominantColorsAnnotation', + 'EntityAnnotation', + 'FaceAnnotation', + 'Feature', + 'GcsDestination', + 'GcsSource', + 'Image', + 'ImageAnnotationContext', + 'ImageContext', + 'ImageProperties', + 'ImageSource', + 'InputConfig', + 'LatLongRect', + 'LocalizedObjectAnnotation', + 'LocationInfo', + 'OperationMetadata', + 'OutputConfig', + 'Property', + 'SafeSearchAnnotation', + 'TextDetectionParams', + 'WebDetectionParams', + 'Likelihood', + 'ProductSearchParams', + 'ProductSearchResults', + 'AddProductToProductSetRequest', + 'BatchOperationMetadata', + 'CreateProductRequest', + 'CreateProductSetRequest', + 'CreateReferenceImageRequest', + 'DeleteProductRequest', + 'DeleteProductSetRequest', + 'DeleteReferenceImageRequest', + 'GetProductRequest', + 'GetProductSetRequest', + 'GetReferenceImageRequest', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ListProductsRequest', + 'ListProductsResponse', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'Product', + 'ProductSet', + 'ProductSetPurgeConfig', + 'PurgeProductsRequest', + 'ReferenceImage', + 'RemoveProductFromProductSetRequest', + 'UpdateProductRequest', + 'UpdateProductSetRequest', + 'Block', + 'Page', + 'Paragraph', + 'Symbol', + 'TextAnnotation', + 'Word', + 'WebDetection', +) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py new file mode 100644 index 00000000..5bf133ea --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py @@ -0,0 +1,97 @@ +# -*- 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.vision.v1p4beta1', + manifest={ + 'FaceRecognitionParams', + 'Celebrity', + 'FaceRecognitionResult', + }, +) + + +class FaceRecognitionParams(proto.Message): + r"""Parameters for a celebrity recognition request. + + Attributes: + celebrity_set (Sequence[str]): + The resource names for one or more + [CelebritySet][google.cloud.vision.v1p4beta1.CelebritySet]s. + A celebrity set is preloaded and can be specified as + "builtin/default". If this is specified, the algorithm will + try to match the faces detected in the input image to the + Celebrities in the CelebritySets. + """ + + celebrity_set = proto.RepeatedField( + proto.STRING, + number=1, + ) + + +class Celebrity(proto.Message): + r"""A Celebrity is a group of Faces with an identity. + + Attributes: + name (str): + The resource name of the preloaded Celebrity. Has the format + ``builtin/{mid}``. + display_name (str): + The Celebrity's display name. + description (str): + The Celebrity's description. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + + +class FaceRecognitionResult(proto.Message): + r"""Information about a face's identity. + + Attributes: + celebrity (google.cloud.vision_v1p4beta1.types.Celebrity): + The [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] + that this face was matched to. + confidence (float): + Recognition confidence. Range [0, 1]. + """ + + celebrity = proto.Field( + proto.MESSAGE, + number=1, + message='Celebrity', + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py new file mode 100644 index 00000000..fc03a711 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py @@ -0,0 +1,125 @@ +# -*- 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.vision.v1p4beta1', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + 'Position', + }, +) + + +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.vision_v1p4beta1.types.Vertex]): + The bounding polygon vertices. + normalized_vertices (Sequence[google.cloud.vision_v1p4beta1.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', + ) + + +class Position(proto.Message): + r"""A 3D position in the image, used primarily for Face detection + landmarks. A valid Position must have both x and y coordinates. + The position coordinates are in the same scale as the original + image. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate. + z (float): + Z coordinate (or depth). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + z = proto.Field( + proto.FLOAT, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py new file mode 100644 index 00000000..b0a73495 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py @@ -0,0 +1,1518 @@ +# -*- 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.vision_v1p4beta1.types import face +from google.cloud.vision_v1p4beta1.types import geometry +from google.cloud.vision_v1p4beta1.types import product_search +from google.cloud.vision_v1p4beta1.types import text_annotation +from google.cloud.vision_v1p4beta1.types import web_detection as gcv_web_detection +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 latlng_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p4beta1', + manifest={ + 'Likelihood', + 'Feature', + 'ImageSource', + 'Image', + 'FaceAnnotation', + 'LocationInfo', + 'Property', + 'EntityAnnotation', + 'LocalizedObjectAnnotation', + 'SafeSearchAnnotation', + 'LatLongRect', + 'ColorInfo', + 'DominantColorsAnnotation', + 'ImageProperties', + 'CropHint', + 'CropHintsAnnotation', + 'CropHintsParams', + 'WebDetectionParams', + 'TextDetectionParams', + 'ImageContext', + 'AnnotateImageRequest', + 'ImageAnnotationContext', + 'AnnotateImageResponse', + 'BatchAnnotateImagesRequest', + 'BatchAnnotateImagesResponse', + 'AnnotateFileRequest', + 'AnnotateFileResponse', + 'BatchAnnotateFilesRequest', + 'BatchAnnotateFilesResponse', + 'AsyncAnnotateFileRequest', + 'AsyncAnnotateFileResponse', + 'AsyncBatchAnnotateImagesRequest', + 'AsyncBatchAnnotateImagesResponse', + 'AsyncBatchAnnotateFilesRequest', + 'AsyncBatchAnnotateFilesResponse', + 'InputConfig', + 'OutputConfig', + 'GcsSource', + 'GcsDestination', + 'OperationMetadata', + }, +) + + +class Likelihood(proto.Enum): + r"""A bucketized representation of likelihood, which is intended + to give clients highly stable results across model upgrades. + """ + UNKNOWN = 0 + VERY_UNLIKELY = 1 + UNLIKELY = 2 + POSSIBLE = 3 + LIKELY = 4 + VERY_LIKELY = 5 + + +class Feature(proto.Message): + r"""The type of Google Cloud Vision API detection to perform, and the + maximum number of results to return for that type. Multiple + ``Feature`` objects can be specified in the ``features`` list. + + Attributes: + type_ (google.cloud.vision_v1p4beta1.types.Feature.Type): + The feature type. + max_results (int): + Maximum number of results of this type. Does not apply to + ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or + ``CROP_HINTS``. + model (str): + Model to use for the feature. + Supported values: "builtin/stable" (the default + if unset) and "builtin/latest". + """ + class Type(proto.Enum): + r"""Type of Google Cloud Vision API feature to be extracted.""" + TYPE_UNSPECIFIED = 0 + FACE_DETECTION = 1 + LANDMARK_DETECTION = 2 + LOGO_DETECTION = 3 + LABEL_DETECTION = 4 + TEXT_DETECTION = 5 + DOCUMENT_TEXT_DETECTION = 11 + SAFE_SEARCH_DETECTION = 6 + IMAGE_PROPERTIES = 7 + CROP_HINTS = 9 + WEB_DETECTION = 10 + PRODUCT_SEARCH = 12 + OBJECT_LOCALIZATION = 19 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum=Type, + ) + max_results = proto.Field( + proto.INT32, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + + +class ImageSource(proto.Message): + r"""External image source (Google Cloud Storage or web URL image + location). + + Attributes: + gcs_image_uri (str): + **Use ``image_uri`` instead.** + + The 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. + image_uri (str): + The URI of the source image. Can be either: + + 1. A 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. + + 2. A publicly-accessible image HTTP/HTTPS URL. When fetching + images from HTTP/HTTPS URLs, Google cannot guarantee that + the request will be completed. Your request may fail if + the specified host denies the request (e.g. due to + request throttling or DOS prevention), or if Google + throttles requests to the site for abuse prevention. You + should not depend on externally-hosted images for + production applications. + + When both ``gcs_image_uri`` and ``image_uri`` are specified, + ``image_uri`` takes precedence. + """ + + gcs_image_uri = proto.Field( + proto.STRING, + number=1, + ) + image_uri = proto.Field( + proto.STRING, + number=2, + ) + + +class Image(proto.Message): + r"""Client image to perform Google Cloud Vision API tasks over. + + Attributes: + content (bytes): + Image content, represented as a stream of bytes. Note: As + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + source (google.cloud.vision_v1p4beta1.types.ImageSource): + Google Cloud Storage image location, or publicly-accessible + image URL. If both ``content`` and ``source`` are provided + for an image, ``content`` takes precedence and is used to + perform the image annotation request. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + source = proto.Field( + proto.MESSAGE, + number=2, + message='ImageSource', + ) + + +class FaceAnnotation(proto.Message): + r"""A face annotation object contains the results of face + detection. + + Attributes: + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding polygon around the face. The coordinates of the + bounding box are in the original image's scale. The bounding + box is computed to "frame" the face in accordance with human + expectations. It is based on the landmarker results. Note + that one or more x and/or y coordinates may not be generated + in the ``BoundingPoly`` (the polygon will be unbounded) if + only a partial face appears in the image to be annotated. + fd_bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The ``fd_bounding_poly`` bounding polygon is tighter than + the ``boundingPoly``, and encloses only the skin part of the + face. Typically, it is used to eliminate the face from any + image analysis that detects the "amount of skin" visible in + an image. It is not based on the landmarker results, only on + the initial face detection, hence the fd (face detection) + prefix. + landmarks (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark]): + Detected face landmarks. + roll_angle (float): + Roll angle, which indicates the amount of + clockwise/anti-clockwise rotation of the face relative to + the image vertical about the axis perpendicular to the face. + Range [-180,180]. + pan_angle (float): + Yaw angle, which indicates the leftward/rightward angle that + the face is pointing relative to the vertical plane + perpendicular to the image. Range [-180,180]. + tilt_angle (float): + Pitch angle, which indicates the upwards/downwards angle + that the face is pointing relative to the image's horizontal + plane. Range [-180,180]. + detection_confidence (float): + Detection confidence. Range [0, 1]. + landmarking_confidence (float): + Face landmarking confidence. Range [0, 1]. + joy_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Joy likelihood. + sorrow_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Sorrow likelihood. + anger_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Anger likelihood. + surprise_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Surprise likelihood. + under_exposed_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Under-exposed likelihood. + blurred_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Blurred likelihood. + headwear_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): + Headwear likelihood. + recognition_result (Sequence[google.cloud.vision_v1p4beta1.types.FaceRecognitionResult]): + Additional recognition information. Only computed if + image_context.face_recognition_params is provided, **and** a + match is found to a + [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] in the + input + [CelebritySet][google.cloud.vision.v1p4beta1.CelebritySet]. + This field is sorted in order of decreasing confidence + values. + """ + + class Landmark(proto.Message): + r"""A face-specific landmark (for example, a face feature). + + Attributes: + type_ (google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark.Type): + Face landmark type. + position (google.cloud.vision_v1p4beta1.types.Position): + Face landmark position. + """ + class Type(proto.Enum): + r"""Face landmark (feature) type. Left and right are defined from the + vantage of the viewer of the image without considering mirror + projections typical of photos. So, ``LEFT_EYE``, typically, is the + person's right eye. + """ + UNKNOWN_LANDMARK = 0 + LEFT_EYE = 1 + RIGHT_EYE = 2 + LEFT_OF_LEFT_EYEBROW = 3 + RIGHT_OF_LEFT_EYEBROW = 4 + LEFT_OF_RIGHT_EYEBROW = 5 + RIGHT_OF_RIGHT_EYEBROW = 6 + MIDPOINT_BETWEEN_EYES = 7 + NOSE_TIP = 8 + UPPER_LIP = 9 + LOWER_LIP = 10 + MOUTH_LEFT = 11 + MOUTH_RIGHT = 12 + MOUTH_CENTER = 13 + NOSE_BOTTOM_RIGHT = 14 + NOSE_BOTTOM_LEFT = 15 + NOSE_BOTTOM_CENTER = 16 + LEFT_EYE_TOP_BOUNDARY = 17 + LEFT_EYE_RIGHT_CORNER = 18 + LEFT_EYE_BOTTOM_BOUNDARY = 19 + LEFT_EYE_LEFT_CORNER = 20 + RIGHT_EYE_TOP_BOUNDARY = 21 + RIGHT_EYE_RIGHT_CORNER = 22 + RIGHT_EYE_BOTTOM_BOUNDARY = 23 + RIGHT_EYE_LEFT_CORNER = 24 + LEFT_EYEBROW_UPPER_MIDPOINT = 25 + RIGHT_EYEBROW_UPPER_MIDPOINT = 26 + LEFT_EAR_TRAGION = 27 + RIGHT_EAR_TRAGION = 28 + LEFT_EYE_PUPIL = 29 + RIGHT_EYE_PUPIL = 30 + FOREHEAD_GLABELLA = 31 + CHIN_GNATHION = 32 + CHIN_LEFT_GONION = 33 + CHIN_RIGHT_GONION = 34 + + type_ = proto.Field( + proto.ENUM, + number=3, + enum='FaceAnnotation.Landmark.Type', + ) + position = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.Position, + ) + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + fd_bounding_poly = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + landmarks = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Landmark, + ) + roll_angle = proto.Field( + proto.FLOAT, + number=4, + ) + pan_angle = proto.Field( + proto.FLOAT, + number=5, + ) + tilt_angle = proto.Field( + proto.FLOAT, + number=6, + ) + detection_confidence = proto.Field( + proto.FLOAT, + number=7, + ) + landmarking_confidence = proto.Field( + proto.FLOAT, + number=8, + ) + joy_likelihood = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + sorrow_likelihood = proto.Field( + proto.ENUM, + number=10, + enum='Likelihood', + ) + anger_likelihood = proto.Field( + proto.ENUM, + number=11, + enum='Likelihood', + ) + surprise_likelihood = proto.Field( + proto.ENUM, + number=12, + enum='Likelihood', + ) + under_exposed_likelihood = proto.Field( + proto.ENUM, + number=13, + enum='Likelihood', + ) + blurred_likelihood = proto.Field( + proto.ENUM, + number=14, + enum='Likelihood', + ) + headwear_likelihood = proto.Field( + proto.ENUM, + number=15, + enum='Likelihood', + ) + recognition_result = proto.RepeatedField( + proto.MESSAGE, + number=16, + message=face.FaceRecognitionResult, + ) + + +class LocationInfo(proto.Message): + r"""Detected entity location information. + + Attributes: + lat_lng (google.type.latlng_pb2.LatLng): + lat/long location coordinates. + """ + + lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + + +class Property(proto.Message): + r"""A ``Property`` consists of a user-supplied name/value pair. + + Attributes: + name (str): + Name of the property. + value (str): + Value of the property. + uint64_value (int): + Value of numeric properties. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + uint64_value = proto.Field( + proto.UINT64, + number=3, + ) + + +class EntityAnnotation(proto.Message): + r"""Set of detected entity features. + + Attributes: + mid (str): + Opaque entity ID. Some IDs may be available in `Google + Knowledge Graph Search + API `__. + locale (str): + The language code for the locale in which the entity textual + ``description`` is expressed. + description (str): + Entity textual description, expressed in its ``locale`` + language. + score (float): + Overall score of the result. Range [0, 1]. + confidence (float): + **Deprecated. Use ``score`` instead.** The accuracy of the + entity detection in an image. For example, for an image in + which the "Eiffel Tower" entity is detected, this field + represents the confidence that there is a tower in the query + image. Range [0, 1]. + topicality (float): + The relevancy of the ICA (Image Content Annotation) label to + the image. For example, the relevancy of "tower" is likely + higher to an image containing the detected "Eiffel Tower" + than to an image containing a detected distant towering + building, even though the confidence that there is a tower + in each image may be the same. Range [0, 1]. + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + Image region to which this entity belongs. Not produced for + ``LABEL_DETECTION`` features. + locations (Sequence[google.cloud.vision_v1p4beta1.types.LocationInfo]): + The location information for the detected entity. Multiple + ``LocationInfo`` elements can be present because one + location may indicate the location of the scene in the + image, and another location may indicate the location of the + place where the image was taken. Location information is + usually present for landmarks. + properties (Sequence[google.cloud.vision_v1p4beta1.types.Property]): + Some entities may have optional user-supplied ``Property`` + (name/value) fields, such a score or string that qualifies + the entity. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + locale = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + topicality = proto.Field( + proto.FLOAT, + number=6, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=7, + message=geometry.BoundingPoly, + ) + locations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='LocationInfo', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Property', + ) + + +class LocalizedObjectAnnotation(proto.Message): + r"""Set of detected objects with bounding boxes. + + Attributes: + mid (str): + Object ID that should align with + EntityAnnotation mid. + 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. + name (str): + Object name, expressed in its ``language_code`` language. + score (float): + Score of the result. Range [0, 1]. + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + Image region to which this object belongs. + This must be populated. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + name = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=5, + message=geometry.BoundingPoly, + ) + + +class SafeSearchAnnotation(proto.Message): + r"""Set of features pertaining to the image, computed by computer + vision methods over safe-search verticals (for example, adult, + spoof, medical, violence). + + Attributes: + adult (google.cloud.vision_v1p4beta1.types.Likelihood): + Represents the adult content likelihood for + the image. Adult content may contain elements + such as nudity, pornographic images or cartoons, + or sexual activities. + spoof (google.cloud.vision_v1p4beta1.types.Likelihood): + Spoof likelihood. The likelihood that an + modification was made to the image's canonical + version to make it appear funny or offensive. + medical (google.cloud.vision_v1p4beta1.types.Likelihood): + Likelihood that this is a medical image. + violence (google.cloud.vision_v1p4beta1.types.Likelihood): + Likelihood that this image contains violent + content. + racy (google.cloud.vision_v1p4beta1.types.Likelihood): + Likelihood that the request image contains + racy content. Racy content may include (but is + not limited to) skimpy or sheer clothing, + strategically covered nudity, lewd or + provocative poses, or close-ups of sensitive + body areas. + """ + + adult = proto.Field( + proto.ENUM, + number=1, + enum='Likelihood', + ) + spoof = proto.Field( + proto.ENUM, + number=2, + enum='Likelihood', + ) + medical = proto.Field( + proto.ENUM, + number=3, + enum='Likelihood', + ) + violence = proto.Field( + proto.ENUM, + number=4, + enum='Likelihood', + ) + racy = proto.Field( + proto.ENUM, + number=9, + enum='Likelihood', + ) + + +class LatLongRect(proto.Message): + r"""Rectangle determined by min and max ``LatLng`` pairs. + + Attributes: + min_lat_lng (google.type.latlng_pb2.LatLng): + Min lat/long pair. + max_lat_lng (google.type.latlng_pb2.LatLng): + Max lat/long pair. + """ + + min_lat_lng = proto.Field( + proto.MESSAGE, + number=1, + message=latlng_pb2.LatLng, + ) + max_lat_lng = proto.Field( + proto.MESSAGE, + number=2, + message=latlng_pb2.LatLng, + ) + + +class ColorInfo(proto.Message): + r"""Color information consists of RGB channels, score, and the + fraction of the image that the color occupies in the image. + + Attributes: + color (google.type.color_pb2.Color): + RGB components of the color. + score (float): + Image-specific score for this color. Value in range [0, 1]. + pixel_fraction (float): + The fraction of pixels the color occupies in the image. + Value in range [0, 1]. + """ + + color = proto.Field( + proto.MESSAGE, + number=1, + message=color_pb2.Color, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + pixel_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class DominantColorsAnnotation(proto.Message): + r"""Set of dominant colors and their corresponding scores. + + Attributes: + colors (Sequence[google.cloud.vision_v1p4beta1.types.ColorInfo]): + RGB color values with their score and pixel + fraction. + """ + + colors = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ColorInfo', + ) + + +class ImageProperties(proto.Message): + r"""Stores image properties, such as dominant colors. + + Attributes: + dominant_colors (google.cloud.vision_v1p4beta1.types.DominantColorsAnnotation): + If present, dominant colors completed + successfully. + """ + + dominant_colors = proto.Field( + proto.MESSAGE, + number=1, + message='DominantColorsAnnotation', + ) + + +class CropHint(proto.Message): + r"""Single crop hint that is used to generate a new crop when + serving an image. + + Attributes: + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding polygon for the crop region. The + coordinates of the bounding box are in the + original image's scale. + confidence (float): + Confidence of this being a salient region. Range [0, 1]. + importance_fraction (float): + Fraction of importance of this salient region + with respect to the original image. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + importance_fraction = proto.Field( + proto.FLOAT, + number=3, + ) + + +class CropHintsAnnotation(proto.Message): + r"""Set of crop hints that are used to generate new crops when + serving images. + + Attributes: + crop_hints (Sequence[google.cloud.vision_v1p4beta1.types.CropHint]): + Crop hint results. + """ + + crop_hints = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='CropHint', + ) + + +class CropHintsParams(proto.Message): + r"""Parameters for crop hints annotation request. + + Attributes: + aspect_ratios (Sequence[float]): + Aspect ratios in floats, representing the + ratio of the width to the height of the image. + For example, if the desired aspect ratio is 4/3, + the corresponding float value should be 1.33333. + If not specified, the best possible crop is + returned. The number of provided aspect ratios + is limited to a maximum of 16; any aspect ratios + provided after the 16th are ignored. + """ + + aspect_ratios = proto.RepeatedField( + proto.FLOAT, + number=1, + ) + + +class WebDetectionParams(proto.Message): + r"""Parameters for web detection request. + + Attributes: + include_geo_results (bool): + Whether to include results derived from the + geo information in the image. + """ + + include_geo_results = proto.Field( + proto.BOOL, + number=2, + ) + + +class TextDetectionParams(proto.Message): + r"""Parameters for text detections. This is used to control + TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. + + Attributes: + enable_text_detection_confidence_score (bool): + By default, Cloud Vision API only includes confidence score + for DOCUMENT_TEXT_DETECTION result. Set the flag to true to + include confidence score for TEXT_DETECTION as well. + """ + + enable_text_detection_confidence_score = proto.Field( + proto.BOOL, + number=9, + ) + + +class ImageContext(proto.Message): + r"""Image context and/or feature-specific parameters. + + Attributes: + lat_long_rect (google.cloud.vision_v1p4beta1.types.LatLongRect): + Not used. + language_hints (Sequence[str]): + List of languages to use for TEXT_DETECTION. 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). + Text detection returns an error if one or more of the + specified languages is not one of the `supported + languages `__. + crop_hints_params (google.cloud.vision_v1p4beta1.types.CropHintsParams): + Parameters for crop hints annotation request. + face_recognition_params (google.cloud.vision_v1p4beta1.types.FaceRecognitionParams): + Parameters for face recognition. + product_search_params (google.cloud.vision_v1p4beta1.types.ProductSearchParams): + Parameters for product search. + web_detection_params (google.cloud.vision_v1p4beta1.types.WebDetectionParams): + Parameters for web detection. + text_detection_params (google.cloud.vision_v1p4beta1.types.TextDetectionParams): + Parameters for text detection and document + text detection. + """ + + lat_long_rect = proto.Field( + proto.MESSAGE, + number=1, + message='LatLongRect', + ) + language_hints = proto.RepeatedField( + proto.STRING, + number=2, + ) + crop_hints_params = proto.Field( + proto.MESSAGE, + number=4, + message='CropHintsParams', + ) + face_recognition_params = proto.Field( + proto.MESSAGE, + number=10, + message=face.FaceRecognitionParams, + ) + product_search_params = proto.Field( + proto.MESSAGE, + number=5, + message=product_search.ProductSearchParams, + ) + web_detection_params = proto.Field( + proto.MESSAGE, + number=6, + message='WebDetectionParams', + ) + text_detection_params = proto.Field( + proto.MESSAGE, + number=12, + message='TextDetectionParams', + ) + + +class AnnotateImageRequest(proto.Message): + r"""Request for performing Google Cloud Vision API tasks over a + user-provided image, with user-requested features, and with + context information. + + Attributes: + image (google.cloud.vision_v1p4beta1.types.Image): + The image to be processed. + features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): + Requested features. + image_context (google.cloud.vision_v1p4beta1.types.ImageContext): + Additional context that may accompany the + image. + """ + + image = proto.Field( + proto.MESSAGE, + number=1, + message='Image', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + + +class ImageAnnotationContext(proto.Message): + r"""If an image was produced from a file (e.g. a PDF), this + message gives information about the source of that image. + + Attributes: + uri (str): + The URI of the file used to produce the + image. + page_number (int): + If the file was a PDF or TIFF, this field + gives the page number within the file used to + produce the image. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + page_number = proto.Field( + proto.INT32, + number=2, + ) + + +class AnnotateImageResponse(proto.Message): + r"""Response to an image annotation request. + + Attributes: + face_annotations (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation]): + If present, face detection has completed + successfully. + landmark_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): + If present, landmark detection has completed + successfully. + logo_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): + If present, logo detection has completed + successfully. + label_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): + If present, label detection has completed + successfully. + localized_object_annotations (Sequence[google.cloud.vision_v1p4beta1.types.LocalizedObjectAnnotation]): + If present, localized object detection has + completed successfully. This will be sorted + descending by confidence score. + text_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): + If present, text (OCR) detection has + completed successfully. + full_text_annotation (google.cloud.vision_v1p4beta1.types.TextAnnotation): + If present, text (OCR) detection or document + (OCR) text detection has completed successfully. + This annotation provides the structural + hierarchy for the OCR detected text. + safe_search_annotation (google.cloud.vision_v1p4beta1.types.SafeSearchAnnotation): + If present, safe-search annotation has + completed successfully. + image_properties_annotation (google.cloud.vision_v1p4beta1.types.ImageProperties): + If present, image properties were extracted + successfully. + crop_hints_annotation (google.cloud.vision_v1p4beta1.types.CropHintsAnnotation): + If present, crop hints have completed + successfully. + web_detection (google.cloud.vision_v1p4beta1.types.WebDetection): + If present, web detection has completed + successfully. + product_search_results (google.cloud.vision_v1p4beta1.types.ProductSearchResults): + If present, product search has completed + successfully. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the operation. Note + that filled-in image annotations are guaranteed to be + correct, even when ``error`` is set. + context (google.cloud.vision_v1p4beta1.types.ImageAnnotationContext): + If present, contextual information is needed + to understand where this image comes from. + """ + + face_annotations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='FaceAnnotation', + ) + landmark_annotations = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='EntityAnnotation', + ) + logo_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='EntityAnnotation', + ) + label_annotations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='EntityAnnotation', + ) + localized_object_annotations = proto.RepeatedField( + proto.MESSAGE, + number=22, + message='LocalizedObjectAnnotation', + ) + text_annotations = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='EntityAnnotation', + ) + full_text_annotation = proto.Field( + proto.MESSAGE, + number=12, + message=text_annotation.TextAnnotation, + ) + safe_search_annotation = proto.Field( + proto.MESSAGE, + number=6, + message='SafeSearchAnnotation', + ) + image_properties_annotation = proto.Field( + proto.MESSAGE, + number=8, + message='ImageProperties', + ) + crop_hints_annotation = proto.Field( + proto.MESSAGE, + number=11, + message='CropHintsAnnotation', + ) + web_detection = proto.Field( + proto.MESSAGE, + number=13, + message=gcv_web_detection.WebDetection, + ) + product_search_results = proto.Field( + proto.MESSAGE, + number=14, + message=product_search.ProductSearchResults, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + context = proto.Field( + proto.MESSAGE, + number=21, + message='ImageAnnotationContext', + ) + + +class BatchAnnotateImagesRequest(proto.Message): + r"""Multiple image annotation requests are batched into a single + service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + + +class BatchAnnotateImagesResponse(proto.Message): + r"""Response to a batch image annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): + Individual responses to image annotation + requests within the batch. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageResponse', + ) + + +class AnnotateFileRequest(proto.Message): + r"""A request to annotate one single file, e.g. a PDF, TIFF or + GIF file. + + Attributes: + input_config (google.cloud.vision_v1p4beta1.types.InputConfig): + Required. Information about the input file. + features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): + Required. Requested features. + image_context (google.cloud.vision_v1p4beta1.types.ImageContext): + Additional context that may accompany the + image(s) in the file. + pages (Sequence[int]): + Pages of the file to perform image + annotation. + Pages starts from 1, we assume the first page of + the file is page 1. At most 5 pages are + supported per request. Pages can be negative. + Page 1 means the first page. + Page 2 means the second page. + Page -1 means the last page. + Page -2 means the second to the last page. + + If the file is GIF instead of PDF or TIFF, page + refers to GIF frames. + If this field is empty, by default the service + performs image annotation for the first 5 pages + of the file. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + pages = proto.RepeatedField( + proto.INT32, + number=4, + ) + + +class AnnotateFileResponse(proto.Message): + r"""Response to a single file annotation request. A file may + contain one or more images, which individually have their own + responses. + + Attributes: + input_config (google.cloud.vision_v1p4beta1.types.InputConfig): + Information about the file for which this + response is generated. + responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): + Individual responses to images found within the file. This + field will be empty if the ``error`` field is set. + total_pages (int): + This field gives the total number of pages in + the file. + error (google.rpc.status_pb2.Status): + If set, represents the error message for the failed request. + The ``responses`` field will not be set in this case. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + responses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='AnnotateImageResponse', + ) + total_pages = proto.Field( + proto.INT32, + number=3, + ) + error = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + + +class BatchAnnotateFilesRequest(proto.Message): + r"""A list of requests to annotate files using the + BatchAnnotateFiles API. + + Attributes: + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]): + Required. The list of file annotation + requests. Right now we support only one + AnnotateFileRequest in + BatchAnnotateFilesRequest. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateFileRequest', + ) + + +class BatchAnnotateFilesResponse(proto.Message): + r"""A list of file annotation responses. + + Attributes: + responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileResponse]): + The list of file annotation responses, each + response corresponding to each + AnnotateFileRequest in + BatchAnnotateFilesRequest. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateFileResponse', + ) + + +class AsyncAnnotateFileRequest(proto.Message): + r"""An offline file annotation request. + + Attributes: + input_config (google.cloud.vision_v1p4beta1.types.InputConfig): + Required. Information about the input file. + features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): + Required. Requested features. + image_context (google.cloud.vision_v1p4beta1.types.ImageContext): + Additional context that may accompany the + image(s) in the file. + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): + Required. The desired output location and + metadata (e.g. format). + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + features = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Feature', + ) + image_context = proto.Field( + proto.MESSAGE, + number=3, + message='ImageContext', + ) + output_config = proto.Field( + proto.MESSAGE, + number=4, + message='OutputConfig', + ) + + +class AsyncAnnotateFileResponse(proto.Message): + r"""The response for a single offline file annotation request. + + Attributes: + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): + The output location and metadata from + AsyncAnnotateFileRequest. + """ + + output_config = proto.Field( + proto.MESSAGE, + number=1, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateImagesRequest(proto.Message): + r"""Request for async image annotation for a list of images. + + Attributes: + requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): + Required. Individual image annotation + requests for this batch. + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): + Required. The desired output location and + metadata (e.g. format). + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AnnotateImageRequest', + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateImagesResponse(proto.Message): + r"""Response to an async batch image annotation request. + + Attributes: + output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): + The output location and metadata from + AsyncBatchAnnotateImagesRequest. + """ + + output_config = proto.Field( + proto.MESSAGE, + number=1, + message='OutputConfig', + ) + + +class AsyncBatchAnnotateFilesRequest(proto.Message): + r"""Multiple async file annotation requests are batched into a + single service call. + + Attributes: + requests (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]): + Required. Individual async file annotation + requests for this batch. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileRequest', + ) + + +class AsyncBatchAnnotateFilesResponse(proto.Message): + r"""Response to an async batch file annotation request. + + Attributes: + responses (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileResponse]): + The list of file annotation responses, one + for each request in + AsyncBatchAnnotateFilesRequest. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='AsyncAnnotateFileResponse', + ) + + +class InputConfig(proto.Message): + r"""The desired input location and metadata. + + Attributes: + gcs_source (google.cloud.vision_v1p4beta1.types.GcsSource): + The Google Cloud Storage location to read the + input from. + content (bytes): + File content, represented as a stream of bytes. Note: As + with all ``bytes`` fields, protobuffers use a pure binary + representation, whereas JSON representations use base64. + + Currently, this field only works for BatchAnnotateFiles + requests. It does not work for AsyncBatchAnnotateFiles + requests. + mime_type (str): + The type of the file. Currently only + "application/pdf", "image/tiff" and "image/gif" + are supported. Wildcards are not supported. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message='GcsSource', + ) + content = proto.Field( + proto.BYTES, + number=3, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class OutputConfig(proto.Message): + r"""The desired output location and metadata. + + Attributes: + gcs_destination (google.cloud.vision_v1p4beta1.types.GcsDestination): + The Google Cloud Storage location to write + the output(s) to. + batch_size (int): + The max number of response protos to put into each output + JSON file 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 response + protos will be generated. If ``batch_size`` = 20, then 5 + json files each containing 20 response protos will be + written under the prefix ``gcs_destination``.\ ``uri``. + + Currently, batch_size only applies to GcsDestination, with + potential future support for other output configurations. + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message='GcsDestination', + ) + batch_size = proto.Field( + proto.INT32, + number=2, + ) + + +class GcsSource(proto.Message): + r"""The Google Cloud Storage location where the input will be + read from. + + Attributes: + uri (str): + Google Cloud Storage URI for the input file. + This must only be a Google Cloud Storage object. + Wildcards are not currently supported. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class GcsDestination(proto.Message): + r"""The Google Cloud Storage location where the output will be + written to. + + Attributes: + uri (str): + Google Cloud Storage URI prefix where the results will be + stored. Results will be in JSON format and preceded by its + corresponding input URI prefix. This field can either + represent a gcs file prefix or gcs directory. In either + case, the uri should be unique because in order to get all + of the output files, you will need to do a wildcard gcs + search on the uri prefix you provide. + + Examples: + + - File Prefix: gs://bucket-name/here/filenameprefix The + output files will be created in gs://bucket-name/here/ + and the names of the output files will begin with + "filenameprefix". + + - Directory Prefix: gs://bucket-name/some/location/ The + output files will be created in + gs://bucket-name/some/location/ and the names of the + output files could be anything because there was no + filename prefix specified. + + If multiple outputs, each response is still + AnnotateFileResponse, each of which contains some subset of + the full list of AnnotateImageResponse. Multiple outputs can + happen if, for example, the output JSON is too large and + overflows into multiple sharded files. + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class OperationMetadata(proto.Message): + r"""Contains metadata for the BatchAnnotateImages operation. + + Attributes: + state (google.cloud.vision_v1p4beta1.types.OperationMetadata.State): + Current state of the batch operation. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was received. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the operation result was last + updated. + """ + class State(proto.Enum): + r"""Batch operation states.""" + STATE_UNSPECIFIED = 0 + CREATED = 1 + RUNNING = 2 + DONE = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py new file mode 100644 index 00000000..f6290f4a --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py @@ -0,0 +1,222 @@ +# -*- 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.vision_v1p4beta1.types import geometry +from google.cloud.vision_v1p4beta1.types import product_search_service +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p4beta1', + manifest={ + 'ProductSearchParams', + 'ProductSearchResults', + }, +) + + +class ProductSearchParams(proto.Message): + r"""Parameters for a product search request. + + Attributes: + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding polygon around the area of + interest in the image. If it is not specified, + system discretion will be applied. + product_set (str): + The resource name of a + [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] to be + searched for similar images. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. + product_categories (Sequence[str]): + The list of product categories to search in. + Currently, we only consider the first category, + and either "homegoods-v2", "apparel-v2", + "toys-v2", "packagedgoods-v1", or "general-v1" + should be specified. The legacy categories + "homegoods", "apparel", and "toys" are still + supported but will be deprecated. For new + products, please use "homegoods-v2", + "apparel-v2", or "toys-v2" for better product + search accuracy. It is recommended to migrate + existing products to these categories as well. + filter (str): + The filtering expression. This can be used to + restrict search results based on Product labels. + We currently support an AND of OR of key-value + expressions, where each expression within an OR + must have the same key. An '=' should be used to + connect the key and value. + For example, "(color = red OR color = blue) AND + brand = Google" is acceptable, but "(color = red + OR brand = Google)" is not acceptable. "color: + red" is not acceptable because it uses a ':' + instead of an '='. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=9, + message=geometry.BoundingPoly, + ) + product_set = proto.Field( + proto.STRING, + number=6, + ) + product_categories = proto.RepeatedField( + proto.STRING, + number=7, + ) + filter = proto.Field( + proto.STRING, + number=8, + ) + + +class ProductSearchResults(proto.Message): + r"""Results for a product search request. + + Attributes: + index_time (google.protobuf.timestamp_pb2.Timestamp): + Timestamp of the index which provided these + results. Products added to the product set and + products removed from the product set after this + time are not reflected in the current results. + results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.Result]): + List of results, one for each product match. + product_grouped_results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.GroupedResult]): + List of results grouped by products detected + in the query image. Each entry corresponds to + one bounding polygon in the query image, and + contains the matching products specific to that + region. There may be duplicate product matches + in the union of all the per-product results. + """ + + class Result(proto.Message): + r"""Information about a product. + + Attributes: + product (google.cloud.vision_v1p4beta1.types.Product): + The Product. + score (float): + A confidence level on the match, ranging from + 0 (no confidence) to 1 (full confidence). + image (str): + The resource name of the image from the + product that is the closest match to the query. + """ + + product = proto.Field( + proto.MESSAGE, + number=1, + message=product_search_service.Product, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + image = proto.Field( + proto.STRING, + number=3, + ) + + class ObjectAnnotation(proto.Message): + r"""Prediction for what the object in the bounding box is. + + Attributes: + mid (str): + Object ID that should align with + EntityAnnotation mid. + 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. + name (str): + Object name, expressed in its ``language_code`` language. + score (float): + Score of the result. Range [0, 1]. + """ + + mid = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + name = proto.Field( + proto.STRING, + number=3, + ) + score = proto.Field( + proto.FLOAT, + number=4, + ) + + class GroupedResult(proto.Message): + r"""Information about the products similar to a single product in + a query image. + + Attributes: + bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding polygon around the product + detected in the query image. + results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.Result]): + List of results, one for each product match. + object_annotations (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.ObjectAnnotation]): + List of generic predictions for the object in + the bounding box. + """ + + bounding_poly = proto.Field( + proto.MESSAGE, + number=1, + message=geometry.BoundingPoly, + ) + results = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='ProductSearchResults.Result', + ) + object_annotations = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='ProductSearchResults.ObjectAnnotation', + ) + + index_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + results = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Result, + ) + product_grouped_results = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=GroupedResult, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py new file mode 100644 index 00000000..1ca5c357 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py @@ -0,0 +1,1077 @@ +# -*- 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.vision_v1p4beta1.types import geometry +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p4beta1', + manifest={ + 'Product', + 'ProductSet', + 'ReferenceImage', + 'CreateProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'GetProductRequest', + 'UpdateProductRequest', + 'DeleteProductRequest', + 'CreateProductSetRequest', + 'ListProductSetsRequest', + 'ListProductSetsResponse', + 'GetProductSetRequest', + 'UpdateProductSetRequest', + 'DeleteProductSetRequest', + 'CreateReferenceImageRequest', + 'ListReferenceImagesRequest', + 'ListReferenceImagesResponse', + 'GetReferenceImageRequest', + 'DeleteReferenceImageRequest', + 'AddProductToProductSetRequest', + 'RemoveProductFromProductSetRequest', + 'ListProductsInProductSetRequest', + 'ListProductsInProductSetResponse', + 'ImportProductSetsGcsSource', + 'ImportProductSetsInputConfig', + 'ImportProductSetsRequest', + 'ImportProductSetsResponse', + 'BatchOperationMetadata', + 'ProductSetPurgeConfig', + 'PurgeProductsRequest', + }, +) + + +class Product(proto.Message): + r"""A Product contains ReferenceImages. + + Attributes: + name (str): + The resource name of the product. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + + This field is ignored when creating a product. + display_name (str): + The user-provided name for this Product. Must + not be empty. Must be at most 4096 characters + long. + description (str): + User-provided metadata to be stored with this + product. Must be at most 4096 characters long. + product_category (str): + Immutable. The category for the product + identified by the reference image. This should + be either "homegoods-v2", "apparel-v2", or + "toys-v2". The legacy categories "homegoods", + "apparel", and "toys" are still supported, but + these should not be used for new products. + product_labels (Sequence[google.cloud.vision_v1p4beta1.types.Product.KeyValue]): + Key-value pairs that can be attached to a product. At query + time, constraints can be specified based on the + product_labels. + + Note that integer values can be provided as strings, e.g. + "1199". Only strings with integer values can match a + range-based restriction which is to be supported soon. + + Multiple values can be assigned to the same key. One product + may have up to 500 product_labels. + + Notice that the total number of distinct product_labels over + all products in one ProductSet cannot exceed 1M, otherwise + the product search pipeline will refuse to work for that + ProductSet. + """ + + class KeyValue(proto.Message): + r"""A product label represented as a key-value pair. + + Attributes: + key (str): + The key of the label attached to the product. + Cannot be empty and cannot exceed 128 bytes. + value (str): + The value of the label attached to the + product. Cannot be empty and cannot exceed 128 + bytes. + """ + + key = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + product_category = proto.Field( + proto.STRING, + number=4, + ) + product_labels = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=KeyValue, + ) + + +class ProductSet(proto.Message): + r"""A ProductSet contains Products. A ProductSet can contain a + maximum of 1 million reference images. If the limit is exceeded, + periodic indexing will fail. + + Attributes: + name (str): + The resource name of the ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. + + This field is ignored when creating a ProductSet. + display_name (str): + The user-provided name for this ProductSet. + Must not be empty. Must be at most 4096 + characters long. + index_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which this + ProductSet was last indexed. Query results will + reflect all updates before this time. If this + ProductSet has never been indexed, this + timestamp is the default value + "1970-01-01T00:00:00Z". + + This field is ignored when creating a + ProductSet. + index_error (google.rpc.status_pb2.Status): + Output only. If there was an error with + indexing the product set, the field is + populated. + This field is ignored when creating a + ProductSet. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + index_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + index_error = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + + +class ReferenceImage(proto.Message): + r"""A ``ReferenceImage`` represents a product image and its associated + metadata, such as bounding boxes. + + Attributes: + name (str): + The resource name of the reference image. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + + This field is ignored when creating a reference image. + uri (str): + Required. The Google Cloud Storage URI of the reference + image. + + The URI must start with ``gs://``. + bounding_polys (Sequence[google.cloud.vision_v1p4beta1.types.BoundingPoly]): + Optional. Bounding polygons around the areas + of interest in the reference image. If this + field is empty, the system will try to detect + regions of interest. At most 10 bounding + polygons will be used. + The provided shape is converted into a non- + rotated rectangle. Once converted, the small + edge of the rectangle must be greater than or + equal to 300 pixels. The aspect ratio must be + 1:4 or less (i.e. 1:3 is ok; 1:5 is not). + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + uri = proto.Field( + proto.STRING, + number=2, + ) + bounding_polys = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, + ) + + +class CreateProductRequest(proto.Message): + r"""Request message for the ``CreateProduct`` method. + + Attributes: + parent (str): + Required. The project in which the Product should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + product (google.cloud.vision_v1p4beta1.types.Product): + Required. The product to create. + product_id (str): + A user-supplied resource id for this Product. If set, the + server will attempt to use this value as the resource id. If + it is already in use, an error is returned with code + ALREADY_EXISTS. Must be at most 128 characters long. It + cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.MESSAGE, + number=2, + message='Product', + ) + product_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsRequest(proto.Message): + r"""Request message for the ``ListProducts`` method. + + Attributes: + parent (str): + Required. The project OR ProductSet from which Products + should be listed. + + Format: ``projects/PROJECT_ID/locations/LOC_ID`` + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsResponse(proto.Message): + r"""Response message for the ``ListProducts`` method. + + Attributes: + products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): + List of products. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + products = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetProductRequest(proto.Message): + r"""Request message for the ``GetProduct`` method. + + Attributes: + name (str): + Required. Resource name of the Product to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateProductRequest(proto.Message): + r"""Request message for the ``UpdateProduct`` method. + + Attributes: + product (google.cloud.vision_v1p4beta1.types.Product): + Required. The Product resource which replaces + the one on the server. product.name is + immutable. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that specifies + which fields to update. If update_mask isn't specified, all + mutable fields are to be updated. Valid mask paths include + ``product_labels``, ``display_name``, and ``description``. + """ + + product = proto.Field( + proto.MESSAGE, + number=1, + message='Product', + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteProductRequest(proto.Message): + r"""Request message for the ``DeleteProduct`` method. + + Attributes: + name (str): + Required. Resource name of product to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateProductSetRequest(proto.Message): + r"""Request message for the ``CreateProductSet`` method. + + Attributes: + parent (str): + Required. The project in which the ProductSet should be + created. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): + Required. The ProductSet to create. + product_set_id (str): + A user-supplied resource id for this ProductSet. If set, the + server will attempt to use this value as the resource id. If + it is already in use, an error is returned with code + ALREADY_EXISTS. Must be at most 128 characters long. It + cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + product_set = proto.Field( + proto.MESSAGE, + number=2, + message='ProductSet', + ) + product_set_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductSetsRequest(proto.Message): + r"""Request message for the ``ListProductSets`` method. + + Attributes: + parent (str): + Required. The project from which ProductSets should be + listed. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductSetsResponse(proto.Message): + r"""Response message for the ``ListProductSets`` method. + + Attributes: + product_sets (Sequence[google.cloud.vision_v1p4beta1.types.ProductSet]): + List of ProductSets. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + product_sets = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ProductSet', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetProductSetRequest(proto.Message): + r"""Request message for the ``GetProductSet`` method. + + Attributes: + name (str): + Required. Resource name of the ProductSet to get. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateProductSetRequest(proto.Message): + r"""Request message for the ``UpdateProductSet`` method. + + Attributes: + product_set (google.cloud.vision_v1p4beta1.types.ProductSet): + Required. The ProductSet resource which + replaces the one on the server. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The [FieldMask][google.protobuf.FieldMask] that specifies + which fields to update. If update_mask isn't specified, all + mutable fields are to be updated. Valid mask path is + ``display_name``. + """ + + product_set = proto.Field( + proto.MESSAGE, + number=1, + message='ProductSet', + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteProductSetRequest(proto.Message): + r"""Request message for the ``DeleteProductSet`` method. + + Attributes: + name (str): + Required. Resource name of the ProductSet to delete. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateReferenceImageRequest(proto.Message): + r"""Request message for the ``CreateReferenceImage`` method. + + Attributes: + parent (str): + Required. Resource name of the product in which to create + the reference image. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + reference_image (google.cloud.vision_v1p4beta1.types.ReferenceImage): + Required. The reference image to create. + If an image ID is specified, it is ignored. + reference_image_id (str): + A user-supplied resource id for the ReferenceImage to be + added. If set, the server will attempt to use this value as + the resource id. If it is already in use, an error is + returned with code ALREADY_EXISTS. Must be at most 128 + characters long. It cannot contain the character ``/``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + reference_image = proto.Field( + proto.MESSAGE, + number=2, + message='ReferenceImage', + ) + reference_image_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ListReferenceImagesRequest(proto.Message): + r"""Request message for the ``ListReferenceImages`` method. + + Attributes: + parent (str): + Required. Resource name of the product containing the + reference images. + + Format is + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + A token identifying a page of results to be returned. This + is the value of ``nextPageToken`` returned in a previous + reference image list request. + + Defaults to the first page if not specified. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListReferenceImagesResponse(proto.Message): + r"""Response message for the ``ListReferenceImages`` method. + + Attributes: + reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): + The list of reference images. + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + next_page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + @property + def raw_page(self): + return self + + reference_images = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ReferenceImage', + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + next_page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class GetReferenceImageRequest(proto.Message): + r"""Request message for the ``GetReferenceImage`` method. + + Attributes: + name (str): + Required. The resource name of the ReferenceImage to get. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteReferenceImageRequest(proto.Message): + r"""Request message for the ``DeleteReferenceImage`` method. + + Attributes: + name (str): + Required. The resource name of the reference image to + delete. + + Format is: + + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class AddProductToProductSetRequest(proto.Message): + r"""Request message for the ``AddProductToProductSet`` method. + + Attributes: + name (str): + Required. The resource name for the ProductSet to modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + product (str): + Required. The resource name for the Product to be added to + this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.STRING, + number=2, + ) + + +class RemoveProductFromProductSetRequest(proto.Message): + r"""Request message for the ``RemoveProductFromProductSet`` method. + + Attributes: + name (str): + Required. The resource name for the ProductSet to modify. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + product (str): + Required. The resource name for the Product to be removed + from this ProductSet. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + product = proto.Field( + proto.STRING, + number=2, + ) + + +class ListProductsInProductSetRequest(proto.Message): + r"""Request message for the ``ListProductsInProductSet`` method. + + Attributes: + name (str): + Required. The ProductSet resource for which to retrieve + Products. + + Format is: + ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` + page_size (int): + The maximum number of items to return. + Default 10, maximum 100. + page_token (str): + The next_page_token returned from a previous List request, + if any. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsInProductSetResponse(proto.Message): + r"""Response message for the ``ListProductsInProductSet`` method. + + Attributes: + products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): + The list of Products. + next_page_token (str): + Token to retrieve the next page of results, + or empty if there are no more results in the + list. + """ + + @property + def raw_page(self): + return self + + products = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class ImportProductSetsGcsSource(proto.Message): + r"""The Google Cloud Storage location for a csv file which + preserves a list of ImportProductSetRequests in each line. + + Attributes: + csv_file_uri (str): + The Google Cloud Storage URI of the input csv file. + + The URI must start with ``gs://``. + + The format of the input csv file should be one image per + line. In each line, there are 8 columns. + + 1. image-uri + 2. image-id + 3. product-set-id + 4. product-id + 5. product-category + 6. product-display-name + 7. labels + 8. bounding-poly + + The ``image-uri``, ``product-set-id``, ``product-id``, and + ``product-category`` columns are required. All other columns + are optional. + + If the ``ProductSet`` or ``Product`` specified by the + ``product-set-id`` and ``product-id`` values does not exist, + then the system will create a new ``ProductSet`` or + ``Product`` for the image. In this case, the + ``product-display-name`` column refers to + [display_name][google.cloud.vision.v1p4beta1.Product.display_name], + the ``product-category`` column refers to + [product_category][google.cloud.vision.v1p4beta1.Product.product_category], + and the ``labels`` column refers to + [product_labels][google.cloud.vision.v1p4beta1.Product.product_labels]. + + The ``image-id`` column is optional but must be unique if + provided. If it is empty, the system will automatically + assign a unique id to the image. + + The ``product-display-name`` column is optional. If it is + empty, the system sets the + [display_name][google.cloud.vision.v1p4beta1.Product.display_name] + field for the product to a space (" "). You can update the + ``display_name`` later by using the API. + + If a ``Product`` with the specified ``product-id`` already + exists, then the system ignores the + ``product-display-name``, ``product-category``, and + ``labels`` columns. + + The ``labels`` column (optional) is a line containing a list + of comma-separated key-value pairs, in the following format: + + :: + + "key_1=value_1,key_2=value_2,...,key_n=value_n" + + The ``bounding-poly`` column (optional) identifies one + region of interest from the image in the same manner as + ``CreateReferenceImage``. If you do not specify the + ``bounding-poly`` column, then the system will try to detect + regions of interest automatically. + + At most one ``bounding-poly`` column is allowed per line. If + the image contains multiple regions of interest, add a line + to the CSV file that includes the same product information, + and the ``bounding-poly`` values for each region of + interest. + + The ``bounding-poly`` column must contain an even number of + comma-separated numbers, in the format + "p1_x,p1_y,p2_x,p2_y,...,pn_x,pn_y". Use non-negative + integers for absolute bounding polygons, and float values in + [0, 1] for normalized bounding polygons. + + The system will resize the image if the image resolution is + too large to process (larger than 20MP). + """ + + csv_file_uri = proto.Field( + proto.STRING, + number=1, + ) + + +class ImportProductSetsInputConfig(proto.Message): + r"""The input content for the ``ImportProductSets`` method. + + Attributes: + gcs_source (google.cloud.vision_v1p4beta1.types.ImportProductSetsGcsSource): + The Google Cloud Storage location for a csv + file which preserves a list of + ImportProductSetRequests in each line. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + oneof='source', + message='ImportProductSetsGcsSource', + ) + + +class ImportProductSetsRequest(proto.Message): + r"""Request message for the ``ImportProductSets`` method. + + Attributes: + parent (str): + Required. The project in which the ProductSets should be + imported. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + input_config (google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig): + Required. The input content for the list of + requests. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + input_config = proto.Field( + proto.MESSAGE, + number=2, + message='ImportProductSetsInputConfig', + ) + + +class ImportProductSetsResponse(proto.Message): + r"""Response message for the ``ImportProductSets`` method. + + This message is returned by the + [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] + method in the returned + [google.longrunning.Operation.response][google.longrunning.Operation.response] + field. + + Attributes: + reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): + The list of reference_images that are imported successfully. + statuses (Sequence[google.rpc.status_pb2.Status]): + The rpc status for each ImportProductSet request, including + both successes and errors. + + The number of statuses here matches the number of lines in + the csv file, and statuses[i] stores the success or failure + status of processing the i-th line of the csv, starting from + line 0. + """ + + reference_images = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ReferenceImage', + ) + statuses = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + + +class BatchOperationMetadata(proto.Message): + r"""Metadata for the batch operations such as the current state. + + This is included in the ``metadata`` field of the ``Operation`` + returned by the ``GetOperation`` call of the + ``google::longrunning::Operations`` service. + + Attributes: + state (google.cloud.vision_v1p4beta1.types.BatchOperationMetadata.State): + The current state of the batch operation. + submit_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request was submitted + to the server. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the batch request is finished and + [google.longrunning.Operation.done][google.longrunning.Operation.done] + is set to true. + """ + class State(proto.Enum): + r"""Enumerates the possible states that the batch request can be + in. + """ + STATE_UNSPECIFIED = 0 + PROCESSING = 1 + SUCCESSFUL = 2 + FAILED = 3 + CANCELLED = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + submit_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +class ProductSetPurgeConfig(proto.Message): + r"""Config to control which ProductSet contains the Products to + be deleted. + + Attributes: + product_set_id (str): + The ProductSet that contains the Products to delete. If a + Product is a member of product_set_id in addition to other + ProductSets, the Product will still be deleted. + """ + + product_set_id = proto.Field( + proto.STRING, + number=1, + ) + + +class PurgeProductsRequest(proto.Message): + r"""Request message for the ``PurgeProducts`` method. + + Attributes: + product_set_purge_config (google.cloud.vision_v1p4beta1.types.ProductSetPurgeConfig): + Specify which ProductSet contains the + Products to be deleted. + delete_orphan_products (bool): + If delete_orphan_products is true, all Products that are not + in any ProductSet will be deleted. + parent (str): + Required. The project and location in which the Products + should be deleted. + + Format is ``projects/PROJECT_ID/locations/LOC_ID``. + force (bool): + The default value is false. Override this + value to true to actually perform the purge. + """ + + product_set_purge_config = proto.Field( + proto.MESSAGE, + number=2, + oneof='target', + message='ProductSetPurgeConfig', + ) + delete_orphan_products = proto.Field( + proto.BOOL, + number=3, + oneof='target', + ) + parent = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py new file mode 100644 index 00000000..09ebaef0 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py @@ -0,0 +1,393 @@ +# -*- 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.vision_v1p4beta1.types import geometry + + +__protobuf__ = proto.module( + package='google.cloud.vision.v1p4beta1', + manifest={ + 'TextAnnotation', + 'Page', + 'Block', + 'Paragraph', + 'Word', + 'Symbol', + }, +) + + +class TextAnnotation(proto.Message): + r"""TextAnnotation contains a structured representation of OCR extracted + text. The hierarchy of an OCR extracted text structure is like this: + TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each + structural component, starting from Page, may further have their own + properties. Properties describe detected languages, breaks etc.. + Please refer to the + [TextAnnotation.TextProperty][google.cloud.vision.v1p4beta1.TextAnnotation.TextProperty] + message definition below for more detail. + + Attributes: + pages (Sequence[google.cloud.vision_v1p4beta1.types.Page]): + List of pages detected by OCR. + text (str): + UTF-8 text detected on the pages. + """ + + 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, + ) + + class DetectedBreak(proto.Message): + r"""Detected start or end of a structural component. + + Attributes: + type_ (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak.BreakType): + Detected break type. + is_prefix (bool): + True if break prepends the element. + """ + class BreakType(proto.Enum): + r"""Enum to denote the type of break found. New line, space etc.""" + UNKNOWN = 0 + SPACE = 1 + SURE_SPACE = 2 + EOL_SURE_SPACE = 3 + HYPHEN = 4 + LINE_BREAK = 5 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='TextAnnotation.DetectedBreak.BreakType', + ) + is_prefix = proto.Field( + proto.BOOL, + number=2, + ) + + class TextProperty(proto.Message): + r"""Additional information detected on the structural component. + + Attributes: + detected_languages (Sequence[google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedLanguage]): + A list of detected languages together with + confidence. + detected_break (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak): + Detected start or end of a text segment. + """ + + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='TextAnnotation.DetectedLanguage', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='TextAnnotation.DetectedBreak', + ) + + pages = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Page', + ) + text = proto.Field( + proto.STRING, + number=2, + ) + + +class Page(proto.Message): + r"""Detected page from OCR. + + Attributes: + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): + Additional information detected on the page. + width (int): + Page width. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + height (int): + Page height. For PDFs the unit is points. For + images (including TIFFs) the unit is pixels. + blocks (Sequence[google.cloud.vision_v1p4beta1.types.Block]): + List of blocks of text, images etc on this + page. + confidence (float): + Confidence of the OCR results on the page. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + width = proto.Field( + proto.INT32, + number=2, + ) + height = proto.Field( + proto.INT32, + number=3, + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Block', + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Block(proto.Message): + r"""Logical element on the page. + + Attributes: + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + block. + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding box for the block. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: + + :: + + 0----1 + | | + 3----2 + + - when it's rotated 180 degrees around the top-left corner + it becomes: + + :: + + 2----3 + | | + 1----0 + + and the vertex order will still be (0, 1, 2, 3). + paragraphs (Sequence[google.cloud.vision_v1p4beta1.types.Paragraph]): + List of paragraphs in this block (if this + blocks is of type text). + block_type (google.cloud.vision_v1p4beta1.types.Block.BlockType): + Detected block type (text, image etc) for + this block. + confidence (float): + Confidence of the OCR results on the block. Range [0, 1]. + """ + class BlockType(proto.Enum): + r"""Type of a block (text, image etc) as identified by OCR.""" + UNKNOWN = 0 + TEXT = 1 + TABLE = 2 + PICTURE = 3 + RULER = 4 + BARCODE = 5 + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Paragraph', + ) + block_type = proto.Field( + proto.ENUM, + number=4, + enum=BlockType, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + +class Paragraph(proto.Message): + r"""Structural unit of text representing a number of words in + certain order. + + Attributes: + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + paragraph. + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding box for the paragraph. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). + words (Sequence[google.cloud.vision_v1p4beta1.types.Word]): + List of all words in this paragraph. + confidence (float): + Confidence of the OCR results for the paragraph. Range [0, + 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + words = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Word', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Word(proto.Message): + r"""A word representation. + + Attributes: + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): + Additional information detected for the word. + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding box for the word. The vertices are in the order + of top-left, top-right, bottom-right, bottom-left. When a + rotation of the bounding box is detected the rotation is + represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). + symbols (Sequence[google.cloud.vision_v1p4beta1.types.Symbol]): + List of symbols in the word. + The order of the symbols follows the natural + reading order. + confidence (float): + Confidence of the OCR results for the word. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + symbols = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Symbol', + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +class Symbol(proto.Message): + r"""A single symbol representation. + + Attributes: + property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): + Additional information detected for the + symbol. + bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): + The bounding box for the symbol. The vertices are in the + order of top-left, top-right, bottom-right, bottom-left. + When a rotation of the bounding box is detected the rotation + is represented as around the top-left corner as defined when + the text is read in the 'natural' orientation. For example: + + - when the text is horizontal it might look like: 0----1 \| + \| 3----2 + - when it's rotated 180 degrees around the top-left corner + it becomes: 2----3 \| \| 1----0 and the vertex order will + still be (0, 1, 2, 3). + text (str): + The actual UTF-8 representation of the + symbol. + confidence (float): + Confidence of the OCR results for the symbol. Range [0, 1]. + """ + + property = proto.Field( + proto.MESSAGE, + number=1, + message='TextAnnotation.TextProperty', + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + text = proto.Field( + proto.STRING, + number=3, + ) + confidence = proto.Field( + proto.FLOAT, + number=4, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py new file mode 100644 index 00000000..15b2d359 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py @@ -0,0 +1,201 @@ +# -*- 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.vision.v1p4beta1', + manifest={ + 'WebDetection', + }, +) + + +class WebDetection(proto.Message): + r"""Relevant information for the image from the Internet. + + Attributes: + web_entities (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebEntity]): + Deduced entities from similar images on the + Internet. + full_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): + Fully matching images from the Internet. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): + Partial matching images from the Internet. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + pages_with_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebPage]): + Web pages containing the matching images from + the Internet. + visually_similar_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): + The visually similar image results. + best_guess_labels (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebLabel]): + The service's best guess as to the topic of + the request image. Inferred from similar images + on the open web. + """ + + class WebEntity(proto.Message): + r"""Entity deduced from similar images on the Internet. + + Attributes: + entity_id (str): + Opaque entity ID. + score (float): + Overall relevancy score for the entity. + Not normalized and not comparable across + different image queries. + description (str): + Canonical description of the entity, in + English. + """ + + entity_id = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + + class WebImage(proto.Message): + r"""Metadata for online images. + + Attributes: + url (str): + The result image URL. + score (float): + (Deprecated) Overall relevancy score for the + image. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + + class WebPage(proto.Message): + r"""Metadata for web pages. + + Attributes: + url (str): + The result web page URL. + score (float): + (Deprecated) Overall relevancy score for the + web page. + page_title (str): + Title for the web page, may contain HTML + markups. + full_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): + Fully matching images on the page. + Can include resized copies of the query image. + partial_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): + Partial matching images on the page. + Those images are similar enough to share some + key-point features. For example an original + image will likely have partial matching for its + crops. + """ + + url = proto.Field( + proto.STRING, + number=1, + ) + score = proto.Field( + proto.FLOAT, + number=2, + ) + page_title = proto.Field( + proto.STRING, + number=3, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='WebDetection.WebImage', + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='WebDetection.WebImage', + ) + + class WebLabel(proto.Message): + r"""Label to provide extra metadata for the web detection. + + Attributes: + label (str): + Label for extra metadata. + language_code (str): + The BCP-47 language code for ``label``, such as "en-US" or + "sr-Latn". For more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + """ + + label = proto.Field( + proto.STRING, + number=1, + ) + language_code = proto.Field( + proto.STRING, + number=2, + ) + + web_entities = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=WebEntity, + ) + full_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=WebImage, + ) + partial_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=WebImage, + ) + pages_with_matching_images = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=WebPage, + ) + visually_similar_images = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=WebImage, + ) + best_guess_labels = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=WebLabel, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/mypy.ini b/owl-bot-staging/v1p4beta1/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1p4beta1/noxfile.py b/owl-bot-staging/v1p4beta1/noxfile.py new file mode 100644 index 00000000..d34812ed --- /dev/null +++ b/owl-bot-staging/v1p4beta1/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/vision_v1p4beta1/', + '--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/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py b/owl-bot-staging/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py new file mode 100644 index 00000000..70e802a1 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py @@ -0,0 +1,198 @@ +#! /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 visionCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'add_product_to_product_set': ('name', 'product', ), + 'async_batch_annotate_files': ('requests', ), + 'async_batch_annotate_images': ('requests', 'output_config', ), + 'batch_annotate_files': ('requests', ), + 'batch_annotate_images': ('requests', ), + 'create_product': ('parent', 'product', 'product_id', ), + 'create_product_set': ('parent', 'product_set', 'product_set_id', ), + 'create_reference_image': ('parent', 'reference_image', 'reference_image_id', ), + 'delete_product': ('name', ), + 'delete_product_set': ('name', ), + 'delete_reference_image': ('name', ), + 'get_product': ('name', ), + 'get_product_set': ('name', ), + 'get_reference_image': ('name', ), + 'import_product_sets': ('parent', 'input_config', ), + 'list_products': ('parent', 'page_size', 'page_token', ), + 'list_product_sets': ('parent', 'page_size', 'page_token', ), + 'list_products_in_product_set': ('name', 'page_size', 'page_token', ), + 'list_reference_images': ('parent', 'page_size', 'page_token', ), + 'purge_products': ('parent', 'product_set_purge_config', 'delete_orphan_products', 'force', ), + 'remove_product_from_product_set': ('name', 'product', ), + 'update_product': ('product', 'update_mask', ), + 'update_product_set': ('product_set', 'update_mask', ), + } + + 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: a.keyword.value not 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=visionCallTransformer(), +): + """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 vision 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/v1p4beta1/setup.py b/owl-bot-staging/v1p4beta1/setup.py new file mode 100644 index 00000000..9d03e702 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/setup.py @@ -0,0 +1,54 @@ +# -*- 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-vision', + 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, < 3.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', + 'Programming Language :: Python :: 3.9', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1p4beta1/tests/__init__.py b/owl-bot-staging/v1p4beta1/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p4beta1/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/v1p4beta1/tests/unit/__init__.py b/owl-bot-staging/v1p4beta1/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p4beta1/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/v1p4beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p4beta1/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/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__init__.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__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/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py new file mode 100644 index 00000000..708f48c0 --- /dev/null +++ b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py @@ -0,0 +1,1724 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1p4beta1.services.image_annotator import ImageAnnotatorAsyncClient +from google.cloud.vision_v1p4beta1.services.image_annotator import ImageAnnotatorClient +from google.cloud.vision_v1p4beta1.services.image_annotator import transports +from google.cloud.vision_v1p4beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1p4beta1.types import face +from google.cloud.vision_v1p4beta1.types import geometry +from google.cloud.vision_v1p4beta1.types import image_annotator +from google.cloud.vision_v1p4beta1.types import product_search +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ImageAnnotatorGrpcTransport, "grpc"), + (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ImageAnnotatorClient, + ImageAnnotatorAsyncClient, +]) +def test_image_annotator_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 == 'vision.googleapis.com:443' + + +def test_image_annotator_client_get_transport_class(): + transport = ImageAnnotatorClient.get_transport_class() + available_transports = [ + transports.ImageAnnotatorGrpcTransport, + ] + assert transport in available_transports + + transport = ImageAnnotatorClient.get_transport_class("grpc") + assert transport == transports.ImageAnnotatorGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) +@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), + (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_image_annotator_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, + always_use_jwt_access=True, + ) + + +def test_image_annotator_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ImageAnnotatorClient( + 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, + always_use_jwt_access=True, + ) + + +def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse( + ) + response = client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +def test_batch_annotate_images_from_dict(): + test_batch_annotate_images(request_type=dict) + + +def test_batch_annotate_images_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 = ImageAnnotatorClient( + 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_annotate_images), + '__call__') as call: + client.batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( + )) + response = await client.batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_async_from_dict(): + await test_batch_annotate_images_async(request_type=dict) + + +def test_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +def test_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + + +@pytest.mark.asyncio +async def test_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_images( + image_annotator.BatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + ) + + +def test_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateFilesRequest): + client = ImageAnnotatorClient( + 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_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateFilesResponse( + ) + response = client.batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) + + +def test_batch_annotate_files_from_dict(): + test_batch_annotate_files(request_type=dict) + + +def test_batch_annotate_files_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 = ImageAnnotatorClient( + 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_annotate_files), + '__call__') as call: + client.batch_annotate_files() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateFilesRequest() + + +@pytest.mark.asyncio +async def test_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateFilesRequest): + client = ImageAnnotatorAsyncClient( + 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_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse( + )) + response = await client.batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.BatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) + + +@pytest.mark.asyncio +async def test_batch_annotate_files_async_from_dict(): + await test_batch_annotate_files_async(request_type=dict) + + +def test_batch_annotate_files_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateFilesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_annotate_files( + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +def test_batch_annotate_files_flattened_error(): + client = ImageAnnotatorClient( + 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_annotate_files( + image_annotator.BatchAnnotateFilesRequest(), + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +@pytest.mark.asyncio +async def test_batch_annotate_files_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = image_annotator.BatchAnnotateFilesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_annotate_files( + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +@pytest.mark.asyncio +async def test_batch_annotate_files_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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_annotate_files( + image_annotator.BatchAnnotateFilesRequest(), + requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +def test_async_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): + client = ImageAnnotatorClient( + 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.async_batch_annotate_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.async_batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_async_batch_annotate_images_from_dict(): + test_async_batch_annotate_images(request_type=dict) + + +def test_async_batch_annotate_images_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 = ImageAnnotatorClient( + 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.async_batch_annotate_images), + '__call__') as call: + client.async_batch_annotate_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_images), + '__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.async_batch_annotate_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_async_from_dict(): + await test_async_batch_annotate_images_async(request_type=dict) + + +def test_async_batch_annotate_images_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_images), + '__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.async_batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) + + +def test_async_batch_annotate_images_flattened_error(): + client = ImageAnnotatorClient( + 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.async_batch_annotate_images( + image_annotator.AsyncBatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), + ) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_images), + '__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.async_batch_annotate_images( + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] + assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_images_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_images( + image_annotator.AsyncBatchAnnotateImagesRequest(), + requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], + output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), + ) + + +def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_async_batch_annotate_files_from_dict(): + test_async_batch_annotate_files(request_type=dict) + + +def test_async_batch_annotate_files_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 = ImageAnnotatorClient( + 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.async_batch_annotate_files), + '__call__') as call: + client.async_batch_annotate_files() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files), + '__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.async_batch_annotate_files(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_async_from_dict(): + await test_async_batch_annotate_files_async(request_type=dict) + + +def test_async_batch_annotate_files_flattened(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +def test_async_batch_annotate_files_flattened_error(): + client = ImageAnnotatorClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.async_batch_annotate_files), + '__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.async_batch_annotate_files( + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] + + +@pytest.mark.asyncio +async def test_async_batch_annotate_files_flattened_error_async(): + client = ImageAnnotatorAsyncClient( + 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.async_batch_annotate_files( + image_annotator.AsyncBatchAnnotateFilesRequest(), + requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ImageAnnotatorClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ImageAnnotatorClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ImageAnnotatorGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, +]) +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 = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ImageAnnotatorGrpcTransport, + ) + +def test_image_annotator_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_image_annotator_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ImageAnnotatorTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'batch_annotate_images', + 'batch_annotate_files', + 'async_batch_annotate_images', + 'async_batch_annotate_files', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ImageAnnotatorTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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) + ImageAnnotatorClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ImageAnnotatorGrpcTransport, + transports.ImageAnnotatorGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_image_annotator_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ImageAnnotatorGrpcTransport, grpc_helpers), + (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_image_annotator_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_host_no_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_image_annotator_host_with_port(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_image_annotator_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcTransport( + 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_image_annotator_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ImageAnnotatorGrpcAsyncIOTransport( + 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) +def test_image_annotator_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_image_annotator_grpc_lro_client(): + client = ImageAnnotatorClient( + 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_image_annotator_grpc_lro_async_client(): + client = ImageAnnotatorAsyncClient( + 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_product_path(): + project = "squid" + location = "clam" + product = "whelk" + expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + actual = ImageAnnotatorClient.product_path(project, location, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "project": "octopus", + "location": "oyster", + "product": "nudibranch", + } + path = ImageAnnotatorClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_product_path(path) + assert expected == actual + +def test_product_set_path(): + project = "cuttlefish" + location = "mussel" + product_set = "winkle" + expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + actual = ImageAnnotatorClient.product_set_path(project, location, product_set) + assert expected == actual + + +def test_parse_product_set_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "product_set": "abalone", + } + path = ImageAnnotatorClient.product_set_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_product_set_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ImageAnnotatorClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ImageAnnotatorClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = ImageAnnotatorClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ImageAnnotatorClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ImageAnnotatorClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ImageAnnotatorClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = ImageAnnotatorClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ImageAnnotatorClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ImageAnnotatorClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: + transport_class = ImageAnnotatorClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py new file mode 100644 index 00000000..38de16ac --- /dev/null +++ b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py @@ -0,0 +1,6323 @@ +# -*- 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.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.vision_v1p4beta1.services.product_search import ProductSearchAsyncClient +from google.cloud.vision_v1p4beta1.services.product_search import ProductSearchClient +from google.cloud.vision_v1p4beta1.services.product_search import pagers +from google.cloud.vision_v1p4beta1.services.product_search import transports +from google.cloud.vision_v1p4beta1.services.product_search.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.vision_v1p4beta1.types import geometry +from google.cloud.vision_v1p4beta1.types import product_search_service +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +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 ProductSearchClient._get_default_mtls_endpoint(None) is None + assert ProductSearchClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductSearchClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + ProductSearchClient, + ProductSearchAsyncClient, +]) +def test_product_search_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 == 'vision.googleapis.com:443' + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductSearchGrpcTransport, "grpc"), + (transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_client_service_account_always_use_jwt(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) + + 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=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class", [ + ProductSearchClient, + ProductSearchAsyncClient, +]) +def test_product_search_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 == 'vision.googleapis.com:443' + + +def test_product_search_client_get_transport_class(): + transport = ProductSearchClient.get_transport_class() + available_transports = [ + transports.ProductSearchGrpcTransport, + ] + assert transport in available_transports + + transport = ProductSearchClient.get_transport_class("grpc") + assert transport == transports.ProductSearchGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) +@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) +def test_product_search_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(ProductSearchClient, '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(ProductSearchClient, '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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "true"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "false"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) +@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_product_search_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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + # 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, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_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, + always_use_jwt_access=True, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), + (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_product_search_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, + always_use_jwt_access=True, + ) + + +def test_product_search_client_client_options_from_dict(): + with mock.patch('google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductSearchClient( + 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, + always_use_jwt_access=True, + ) + + +def test_create_product_set(transport: str = 'grpc', request_type=product_search_service.CreateProductSetRequest): + client = ProductSearchClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.create_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_create_product_set_from_dict(): + test_create_product_set(request_type=dict) + + +def test_create_product_set_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 = ProductSearchClient( + 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_product_set), + '__call__') as call: + client.create_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + +@pytest.mark.asyncio +async def test_create_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductSetRequest): + client = ProductSearchAsyncClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.create_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_create_product_set_async_from_dict(): + await test_create_product_set_async(request_type=dict) + + +def test_create_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateProductSetRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.create_product_set(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_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateProductSetRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.create_product_set(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_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_product_set( + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].product_set_id == 'product_set_id_value' + + +def test_create_product_set_flattened_error(): + client = ProductSearchClient( + 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_product_set( + product_search_service.CreateProductSetRequest(), + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_product_set( + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].product_set_id == 'product_set_id_value' + + +@pytest.mark.asyncio +async def test_create_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_set( + product_search_service.CreateProductSetRequest(), + parent='parent_value', + product_set=product_search_service.ProductSet(name='name_value'), + product_set_id='product_set_id_value', + ) + + +def test_list_product_sets(transport: str = 'grpc', request_type=product_search_service.ListProductSetsRequest): + client = ProductSearchClient( + 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_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductSetsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_product_sets_from_dict(): + test_list_product_sets(request_type=dict) + + +def test_list_product_sets_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 = ProductSearchClient( + 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_product_sets), + '__call__') as call: + client.list_product_sets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + +@pytest.mark.asyncio +async def test_list_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductSetsRequest): + client = ProductSearchAsyncClient( + 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_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductSetsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_product_sets_async_from_dict(): + await test_list_product_sets_async(request_type=dict) + + +def test_list_product_sets_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + call.return_value = product_search_service.ListProductSetsResponse() + client.list_product_sets(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_product_sets_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) + await client.list_product_sets(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_product_sets_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_product_sets( + 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_product_sets_flattened_error(): + client = ProductSearchClient( + 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_product_sets( + product_search_service.ListProductSetsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_product_sets_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductSetsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_product_sets( + 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_product_sets_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_sets( + product_search_service.ListProductSetsRequest(), + parent='parent_value', + ) + + +def test_list_product_sets_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_product_sets(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.ProductSet) + for i in results) + +def test_list_product_sets_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + pages = list(client.list_product_sets(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_product_sets_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_product_sets(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, product_search_service.ProductSet) + for i in responses) + +@pytest.mark.asyncio +async def test_list_product_sets_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_product_sets), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + next_page_token='abc', + ), + product_search_service.ListProductSetsResponse( + product_sets=[], + next_page_token='def', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductSetsResponse( + product_sets=[ + product_search_service.ProductSet(), + product_search_service.ProductSet(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_product_sets(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_product_set(transport: str = 'grpc', request_type=product_search_service.GetProductSetRequest): + client = ProductSearchClient( + 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.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.get_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_get_product_set_from_dict(): + test_get_product_set(request_type=dict) + + +def test_get_product_set_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 = ProductSearchClient( + 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.get_product_set), + '__call__') as call: + client.get_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + +@pytest.mark.asyncio +async def test_get_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductSetRequest): + client = ProductSearchAsyncClient( + 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.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.get_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_get_product_set_async_from_dict(): + await test_get_product_set_async(request_type=dict) + + +def test_get_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.get_product_set(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_get_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.get_product_set(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_get_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product_set( + 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_get_product_set_flattened_error(): + client = ProductSearchClient( + 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.get_product_set( + product_search_service.GetProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product_set( + 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_get_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_product_set( + product_search_service.GetProductSetRequest(), + name='name_value', + ) + + +def test_update_product_set(transport: str = 'grpc', request_type=product_search_service.UpdateProductSetRequest): + client = ProductSearchClient( + 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.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + ) + response = client.update_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +def test_update_product_set_from_dict(): + test_update_product_set(request_type=dict) + + +def test_update_product_set_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 = ProductSearchClient( + 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.update_product_set), + '__call__') as call: + client.update_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + +@pytest.mark.asyncio +async def test_update_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductSetRequest): + client = ProductSearchAsyncClient( + 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.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( + name='name_value', + display_name='display_name_value', + )) + response = await client.update_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ProductSet) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + + +@pytest.mark.asyncio +async def test_update_product_set_async_from_dict(): + await test_update_product_set_async(request_type=dict) + + +def test_update_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.UpdateProductSetRequest() + + request.product_set.name = 'product_set.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + call.return_value = product_search_service.ProductSet() + client.update_product_set(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', + 'product_set.name=product_set.name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.UpdateProductSetRequest() + + request.product_set.name = 'product_set.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + await client.update_product_set(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', + 'product_set.name=product_set.name/value', + ) in kw['metadata'] + + +def test_update_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product_set( + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +def test_update_product_set_flattened_error(): + client = ProductSearchClient( + 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.update_product_set( + product_search_service.UpdateProductSetRequest(), + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.asyncio +async def test_update_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ProductSet() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product_set( + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +@pytest.mark.asyncio +async def test_update_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.update_product_set( + product_search_service.UpdateProductSetRequest(), + product_set=product_search_service.ProductSet(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product_set(transport: str = 'grpc', request_type=product_search_service.DeleteProductSetRequest): + client = ProductSearchClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_set_from_dict(): + test_delete_product_set(request_type=dict) + + +def test_delete_product_set_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 = ProductSearchClient( + 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_product_set), + '__call__') as call: + client.delete_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + +@pytest.mark.asyncio +async def test_delete_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductSetRequest): + client = ProductSearchAsyncClient( + 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_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_set_async_from_dict(): + await test_delete_product_set_async(request_type=dict) + + +def test_delete_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + call.return_value = None + client.delete_product_set(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_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_set(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_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product_set( + 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_product_set_flattened_error(): + client = ProductSearchClient( + 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_product_set( + product_search_service.DeleteProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product_set( + 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_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product_set( + product_search_service.DeleteProductSetRequest(), + name='name_value', + ) + + +def test_create_product(transport: str = 'grpc', request_type=product_search_service.CreateProductRequest): + client = ProductSearchClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.create_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_create_product_from_dict(): + test_create_product(request_type=dict) + + +def test_create_product_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 = ProductSearchClient( + 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_product), + '__call__') as call: + client.create_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + +@pytest.mark.asyncio +async def test_create_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductRequest): + client = ProductSearchAsyncClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.create_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_create_product_async_from_dict(): + await test_create_product_async(request_type=dict) + + +def test_create_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateProductRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.create_product(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_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateProductRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.create_product(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_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_product( + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_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].product == product_search_service.Product(name='name_value') + assert args[0].product_id == 'product_id_value' + + +def test_create_product_flattened_error(): + client = ProductSearchClient( + 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_product( + product_search_service.CreateProductRequest(), + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_product( + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_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].product == product_search_service.Product(name='name_value') + assert args[0].product_id == 'product_id_value' + + +@pytest.mark.asyncio +async def test_create_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product( + product_search_service.CreateProductRequest(), + parent='parent_value', + product=product_search_service.Product(name='name_value'), + product_id='product_id_value', + ) + + +def test_list_products(transport: str = 'grpc', request_type=product_search_service.ListProductsRequest): + client = ProductSearchClient( + 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_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_from_dict(): + test_list_products(request_type=dict) + + +def test_list_products_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 = ProductSearchClient( + 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_products), + '__call__') as call: + client.list_products() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + +@pytest.mark.asyncio +async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsRequest): + client = ProductSearchAsyncClient( + 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_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_async_from_dict(): + await test_list_products_async(request_type=dict) + + +def test_list_products_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = product_search_service.ListProductsResponse() + client.list_products(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_products_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) + await client.list_products(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_products_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products( + 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_products_flattened_error(): + client = ProductSearchClient( + 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_products( + product_search_service.ListProductsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_products_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products( + 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_products_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_products( + product_search_service.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_products(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.Product) + for i in results) + +def test_list_products_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products(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_products_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products(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, product_search_service.Product) + for i in responses) + +@pytest.mark.asyncio +async def test_list_products_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_products(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_product(transport: str = 'grpc', request_type=product_search_service.GetProductRequest): + client = ProductSearchClient( + 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.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_get_product_from_dict(): + test_get_product(request_type=dict) + + +def test_get_product_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 = ProductSearchClient( + 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.get_product), + '__call__') as call: + client.get_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + +@pytest.mark.asyncio +async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductRequest): + client = ProductSearchAsyncClient( + 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.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_get_product_async_from_dict(): + await test_get_product_async(request_type=dict) + + +def test_get_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.get_product(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_get_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.get_product(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_get_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product( + 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_get_product_flattened_error(): + client = ProductSearchClient( + 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.get_product( + product_search_service.GetProductRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product( + 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_get_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_product( + product_search_service.GetProductRequest(), + name='name_value', + ) + + +def test_update_product(transport: str = 'grpc', request_type=product_search_service.UpdateProductRequest): + client = ProductSearchClient( + 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.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + ) + response = client.update_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +def test_update_product_from_dict(): + test_update_product(request_type=dict) + + +def test_update_product_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 = ProductSearchClient( + 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.update_product), + '__call__') as call: + client.update_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + +@pytest.mark.asyncio +async def test_update_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductRequest): + client = ProductSearchAsyncClient( + 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.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( + name='name_value', + display_name='display_name_value', + description='description_value', + product_category='product_category_value', + )) + response = await client.update_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.UpdateProductRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.Product) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.description == 'description_value' + assert response.product_category == 'product_category_value' + + +@pytest.mark.asyncio +async def test_update_product_async_from_dict(): + await test_update_product_async(request_type=dict) + + +def test_update_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.UpdateProductRequest() + + request.product.name = 'product.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + call.return_value = product_search_service.Product() + client.update_product(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', + 'product.name=product.name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.UpdateProductRequest() + + request.product.name = 'product.name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + await client.update_product(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', + 'product.name=product.name/value', + ) in kw['metadata'] + + +def test_update_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product( + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +def test_update_product_flattened_error(): + client = ProductSearchClient( + 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.update_product( + product_search_service.UpdateProductRequest(), + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.asyncio +async def test_update_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product( + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) + + +@pytest.mark.asyncio +async def test_update_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.update_product( + product_search_service.UpdateProductRequest(), + product=product_search_service.Product(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product(transport: str = 'grpc', request_type=product_search_service.DeleteProductRequest): + client = ProductSearchClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_from_dict(): + test_delete_product(request_type=dict) + + +def test_delete_product_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 = ProductSearchClient( + 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_product), + '__call__') as call: + client.delete_product() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + +@pytest.mark.asyncio +async def test_delete_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductRequest): + client = ProductSearchAsyncClient( + 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_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteProductRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_async_from_dict(): + await test_delete_product_async(request_type=dict) + + +def test_delete_product_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + call.return_value = None + client.delete_product(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_product_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteProductRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product(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_product_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product( + 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_product_flattened_error(): + client = ProductSearchClient( + 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_product( + product_search_service.DeleteProductRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_product_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product( + 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_product_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_product( + product_search_service.DeleteProductRequest(), + name='name_value', + ) + + +def test_create_reference_image(transport: str = 'grpc', request_type=product_search_service.CreateReferenceImageRequest): + client = ProductSearchClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + ) + response = client.create_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +def test_create_reference_image_from_dict(): + test_create_reference_image(request_type=dict) + + +def test_create_reference_image_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 = ProductSearchClient( + 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_reference_image), + '__call__') as call: + client.create_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_create_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateReferenceImageRequest): + client = ProductSearchAsyncClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + )) + response = await client.create_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.CreateReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +@pytest.mark.asyncio +async def test_create_reference_image_async_from_dict(): + await test_create_reference_image_async(request_type=dict) + + +def test_create_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.CreateReferenceImageRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + call.return_value = product_search_service.ReferenceImage() + client.create_reference_image(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_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.CreateReferenceImageRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + await client.create_reference_image(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_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_reference_image( + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') + assert args[0].reference_image_id == 'reference_image_id_value' + + +def test_create_reference_image_flattened_error(): + client = ProductSearchClient( + 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_reference_image( + product_search_service.CreateReferenceImageRequest(), + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_value', + ) + + +@pytest.mark.asyncio +async def test_create_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_reference_image( + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') + assert args[0].reference_image_id == 'reference_image_id_value' + + +@pytest.mark.asyncio +async def test_create_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_image( + product_search_service.CreateReferenceImageRequest(), + parent='parent_value', + reference_image=product_search_service.ReferenceImage(name='name_value'), + reference_image_id='reference_image_id_value', + ) + + +def test_delete_reference_image(transport: str = 'grpc', request_type=product_search_service.DeleteReferenceImageRequest): + client = ProductSearchClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_reference_image_from_dict(): + test_delete_reference_image(request_type=dict) + + +def test_delete_reference_image_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 = ProductSearchClient( + 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_reference_image), + '__call__') as call: + client.delete_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_delete_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteReferenceImageRequest): + client = ProductSearchAsyncClient( + 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_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.DeleteReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_reference_image_async_from_dict(): + await test_delete_reference_image_async(request_type=dict) + + +def test_delete_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.DeleteReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + call.return_value = None + client.delete_reference_image(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_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.DeleteReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_reference_image(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_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_reference_image( + 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_reference_image_flattened_error(): + client = ProductSearchClient( + 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_reference_image( + product_search_service.DeleteReferenceImageRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_reference_image( + 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_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_image( + product_search_service.DeleteReferenceImageRequest(), + name='name_value', + ) + + +def test_list_reference_images(transport: str = 'grpc', request_type=product_search_service.ListReferenceImagesRequest): + client = ProductSearchClient( + 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_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse( + page_size=951, + next_page_token='next_page_token_value', + ) + response = client.list_reference_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReferenceImagesPager) + assert response.page_size == 951 + assert response.next_page_token == 'next_page_token_value' + + +def test_list_reference_images_from_dict(): + test_list_reference_images(request_type=dict) + + +def test_list_reference_images_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 = ProductSearchClient( + 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_reference_images), + '__call__') as call: + client.list_reference_images() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + +@pytest.mark.asyncio +async def test_list_reference_images_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListReferenceImagesRequest): + client = ProductSearchAsyncClient( + 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_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse( + page_size=951, + next_page_token='next_page_token_value', + )) + response = await client.list_reference_images(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListReferenceImagesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListReferenceImagesAsyncPager) + assert response.page_size == 951 + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_reference_images_async_from_dict(): + await test_list_reference_images_async(request_type=dict) + + +def test_list_reference_images_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListReferenceImagesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + call.return_value = product_search_service.ListReferenceImagesResponse() + client.list_reference_images(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_reference_images_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListReferenceImagesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) + await client.list_reference_images(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_reference_images_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_reference_images( + 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_reference_images_flattened_error(): + client = ProductSearchClient( + 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_reference_images( + product_search_service.ListReferenceImagesRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_reference_images_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListReferenceImagesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_reference_images( + 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_reference_images_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_reference_images( + product_search_service.ListReferenceImagesRequest(), + parent='parent_value', + ) + + +def test_list_reference_images_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_reference_images(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.ReferenceImage) + for i in results) + +def test_list_reference_images_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + pages = list(client.list_reference_images(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_reference_images_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_reference_images(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, product_search_service.ReferenceImage) + for i in responses) + +@pytest.mark.asyncio +async def test_list_reference_images_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_reference_images), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + next_page_token='abc', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[], + next_page_token='def', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + ], + next_page_token='ghi', + ), + product_search_service.ListReferenceImagesResponse( + reference_images=[ + product_search_service.ReferenceImage(), + product_search_service.ReferenceImage(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_reference_images(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_get_reference_image(transport: str = 'grpc', request_type=product_search_service.GetReferenceImageRequest): + client = ProductSearchClient( + 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.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + ) + response = client.get_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +def test_get_reference_image_from_dict(): + test_get_reference_image(request_type=dict) + + +def test_get_reference_image_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 = ProductSearchClient( + 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.get_reference_image), + '__call__') as call: + client.get_reference_image() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + +@pytest.mark.asyncio +async def test_get_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetReferenceImageRequest): + client = ProductSearchAsyncClient( + 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.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( + name='name_value', + uri='uri_value', + )) + response = await client.get_reference_image(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.GetReferenceImageRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, product_search_service.ReferenceImage) + assert response.name == 'name_value' + assert response.uri == 'uri_value' + + +@pytest.mark.asyncio +async def test_get_reference_image_async_from_dict(): + await test_get_reference_image_async(request_type=dict) + + +def test_get_reference_image_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.GetReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + call.return_value = product_search_service.ReferenceImage() + client.get_reference_image(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_get_reference_image_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.GetReferenceImageRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + await client.get_reference_image(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_get_reference_image_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_reference_image( + 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_get_reference_image_flattened_error(): + client = ProductSearchClient( + 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.get_reference_image( + product_search_service.GetReferenceImageRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_get_reference_image_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_reference_image), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ReferenceImage() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_reference_image( + 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_get_reference_image_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.get_reference_image( + product_search_service.GetReferenceImageRequest(), + name='name_value', + ) + + +def test_add_product_to_product_set(transport: str = 'grpc', request_type=product_search_service.AddProductToProductSetRequest): + client = ProductSearchClient( + 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.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.add_product_to_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_add_product_to_product_set_from_dict(): + test_add_product_to_product_set(request_type=dict) + + +def test_add_product_to_product_set_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 = ProductSearchClient( + 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.add_product_to_product_set), + '__call__') as call: + client.add_product_to_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.AddProductToProductSetRequest): + client = ProductSearchAsyncClient( + 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.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.add_product_to_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.AddProductToProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_async_from_dict(): + await test_add_product_to_product_set_async(request_type=dict) + + +def test_add_product_to_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.AddProductToProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + call.return_value = None + client.add_product_to_product_set(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_add_product_to_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.AddProductToProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.add_product_to_product_set(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_add_product_to_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_product_to_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +def test_add_product_to_product_set_flattened_error(): + client = ProductSearchClient( + 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.add_product_to_product_set( + product_search_service.AddProductToProductSetRequest(), + name='name_value', + product='product_value', + ) + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_product_to_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_product_to_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +@pytest.mark.asyncio +async def test_add_product_to_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.add_product_to_product_set( + product_search_service.AddProductToProductSetRequest(), + name='name_value', + product='product_value', + ) + + +def test_remove_product_from_product_set(transport: str = 'grpc', request_type=product_search_service.RemoveProductFromProductSetRequest): + client = ProductSearchClient( + 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.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.remove_product_from_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_remove_product_from_product_set_from_dict(): + test_remove_product_from_product_set(request_type=dict) + + +def test_remove_product_from_product_set_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 = ProductSearchClient( + 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.remove_product_from_product_set), + '__call__') as call: + client.remove_product_from_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.RemoveProductFromProductSetRequest): + client = ProductSearchAsyncClient( + 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.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.remove_product_from_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.RemoveProductFromProductSetRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_async_from_dict(): + await test_remove_product_from_product_set_async(request_type=dict) + + +def test_remove_product_from_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.RemoveProductFromProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + call.return_value = None + client.remove_product_from_product_set(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_remove_product_from_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.RemoveProductFromProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.remove_product_from_product_set(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_remove_product_from_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.remove_product_from_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +def test_remove_product_from_product_set_flattened_error(): + client = ProductSearchClient( + 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.remove_product_from_product_set( + product_search_service.RemoveProductFromProductSetRequest(), + name='name_value', + product='product_value', + ) + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_product_from_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.remove_product_from_product_set( + name='name_value', + product='product_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' + assert args[0].product == 'product_value' + + +@pytest.mark.asyncio +async def test_remove_product_from_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.remove_product_from_product_set( + product_search_service.RemoveProductFromProductSetRequest(), + name='name_value', + product='product_value', + ) + + +def test_list_products_in_product_set(transport: str = 'grpc', request_type=product_search_service.ListProductsInProductSetRequest): + client = ProductSearchClient( + 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_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products_in_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsInProductSetPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_in_product_set_from_dict(): + test_list_products_in_product_set(request_type=dict) + + +def test_list_products_in_product_set_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 = ProductSearchClient( + 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_products_in_product_set), + '__call__') as call: + client.list_products_in_product_set() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsInProductSetRequest): + client = ProductSearchAsyncClient( + 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_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products_in_product_set(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ListProductsInProductSetRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsInProductSetAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async_from_dict(): + await test_list_products_in_product_set_async(request_type=dict) + + +def test_list_products_in_product_set_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ListProductsInProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + call.return_value = product_search_service.ListProductsInProductSetResponse() + client.list_products_in_product_set(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_list_products_in_product_set_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ListProductsInProductSetRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) + await client.list_products_in_product_set(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_list_products_in_product_set_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products_in_product_set( + 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_list_products_in_product_set_flattened_error(): + client = ProductSearchClient( + 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_products_in_product_set( + product_search_service.ListProductsInProductSetRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_list_products_in_product_set_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = product_search_service.ListProductsInProductSetResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products_in_product_set( + 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_list_products_in_product_set_flattened_error_async(): + client = ProductSearchAsyncClient( + 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_products_in_product_set( + product_search_service.ListProductsInProductSetRequest(), + name='name_value', + ) + + +def test_list_products_in_product_set_pager(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('name', ''), + )), + ) + pager = client.list_products_in_product_set(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, product_search_service.Product) + for i in results) + +def test_list_products_in_product_set_pages(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products_in_product_set(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_products_in_product_set_async_pager(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products_in_product_set(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, product_search_service.Product) + for i in responses) + +@pytest.mark.asyncio +async def test_list_products_in_product_set_async_pages(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products_in_product_set), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + product_search_service.Product(), + ], + next_page_token='abc', + ), + product_search_service.ListProductsInProductSetResponse( + products=[], + next_page_token='def', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + ], + next_page_token='ghi', + ), + product_search_service.ListProductsInProductSetResponse( + products=[ + product_search_service.Product(), + product_search_service.Product(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_products_in_product_set(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_import_product_sets(transport: str = 'grpc', request_type=product_search_service.ImportProductSetsRequest): + client = ProductSearchClient( + 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.import_product_sets), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.import_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_import_product_sets_from_dict(): + test_import_product_sets(request_type=dict) + + +def test_import_product_sets_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 = ProductSearchClient( + 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.import_product_sets), + '__call__') as call: + client.import_product_sets() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + +@pytest.mark.asyncio +async def test_import_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ImportProductSetsRequest): + client = ProductSearchAsyncClient( + 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.import_product_sets), + '__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.import_product_sets(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.ImportProductSetsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_import_product_sets_async_from_dict(): + await test_import_product_sets_async(request_type=dict) + + +def test_import_product_sets_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.ImportProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.import_product_sets(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_import_product_sets_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.ImportProductSetsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.import_product_sets(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_import_product_sets_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__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.import_product_sets( + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) + + +def test_import_product_sets_flattened_error(): + client = ProductSearchClient( + 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.import_product_sets( + product_search_service.ImportProductSetsRequest(), + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), + ) + + +@pytest.mark.asyncio +async def test_import_product_sets_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_product_sets), + '__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.import_product_sets( + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) + + +@pytest.mark.asyncio +async def test_import_product_sets_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.import_product_sets( + product_search_service.ImportProductSetsRequest(), + parent='parent_value', + input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), + ) + + +def test_purge_products(transport: str = 'grpc', request_type=product_search_service.PurgeProductsRequest): + client = ProductSearchClient( + 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.purge_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.purge_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.PurgeProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_purge_products_from_dict(): + test_purge_products(request_type=dict) + + +def test_purge_products_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 = ProductSearchClient( + 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.purge_products), + '__call__') as call: + client.purge_products() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.PurgeProductsRequest() + + +@pytest.mark.asyncio +async def test_purge_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.PurgeProductsRequest): + client = ProductSearchAsyncClient( + 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.purge_products), + '__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.purge_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == product_search_service.PurgeProductsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_purge_products_async_from_dict(): + await test_purge_products_async(request_type=dict) + + +def test_purge_products_field_headers(): + client = ProductSearchClient( + 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 = product_search_service.PurgeProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.purge_products(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_purge_products_field_headers_async(): + client = ProductSearchAsyncClient( + 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 = product_search_service.PurgeProductsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.purge_products(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_purge_products_flattened(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__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.purge_products( + 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_purge_products_flattened_error(): + client = ProductSearchClient( + 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.purge_products( + product_search_service.PurgeProductsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_purge_products_flattened_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.purge_products), + '__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.purge_products( + 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_purge_products_flattened_error_async(): + client = ProductSearchAsyncClient( + 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.purge_products( + product_search_service.PurgeProductsRequest(), + parent='parent_value', + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductSearchClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductSearchClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductSearchGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductSearchGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, +]) +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 = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductSearchGrpcTransport, + ) + +def test_product_search_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductSearchTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_product_search_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductSearchTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'create_product_set', + 'list_product_sets', + 'get_product_set', + 'update_product_set', + 'delete_product_set', + 'create_product', + 'list_products', + 'get_product', + 'update_product', + 'delete_product', + 'create_reference_image', + 'delete_reference_image', + 'list_reference_images', + 'get_reference_image', + 'add_product_to_product_set', + 'remove_product_from_product_set', + 'list_products_in_product_set', + 'import_product_sets', + 'purge_products', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # 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_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport( + 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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', + ), + quota_project_id="octopus", + ) + + +def test_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductSearchTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_product_search_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) + ProductSearchClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_product_search_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) + ProductSearchClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_product_search_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', 'https://www.googleapis.com/auth/cloud-vision',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductSearchGrpcTransport, + transports.ProductSearchGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_product_search_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', + 'https://www.googleapis.com/auth/cloud-vision', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductSearchGrpcTransport, grpc_helpers), + (transports.ProductSearchGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_product_search_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( + "vision.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/cloud-vision', +), + scopes=["1", "2"], + default_host="vision.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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_product_search_host_no_port(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), + ) + assert client.transport._host == 'vision.googleapis.com:443' + + +def test_product_search_host_with_port(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), + ) + assert client.transport._host == 'vision.googleapis.com:8000' + +def test_product_search_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductSearchGrpcTransport( + 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_product_search_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductSearchGrpcAsyncIOTransport( + 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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) +def test_product_search_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_product_search_grpc_lro_client(): + client = ProductSearchClient( + 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_product_search_grpc_lro_async_client(): + client = ProductSearchAsyncClient( + 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_product_path(): + project = "squid" + location = "clam" + product = "whelk" + expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) + actual = ProductSearchClient.product_path(project, location, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "project": "octopus", + "location": "oyster", + "product": "nudibranch", + } + path = ProductSearchClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_product_path(path) + assert expected == actual + +def test_product_set_path(): + project = "cuttlefish" + location = "mussel" + product_set = "winkle" + expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) + actual = ProductSearchClient.product_set_path(project, location, product_set) + assert expected == actual + + +def test_parse_product_set_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "product_set": "abalone", + } + path = ProductSearchClient.product_set_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_product_set_path(path) + assert expected == actual + +def test_reference_image_path(): + project = "squid" + location = "clam" + product = "whelk" + reference_image = "octopus" + expected = "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) + actual = ProductSearchClient.reference_image_path(project, location, product, reference_image) + assert expected == actual + + +def test_parse_reference_image_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "product": "cuttlefish", + "reference_image": "mussel", + } + path = ProductSearchClient.reference_image_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_reference_image_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductSearchClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = ProductSearchClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductSearchClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = ProductSearchClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductSearchClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = ProductSearchClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format(project=project, ) + actual = ProductSearchClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = ProductSearchClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductSearchClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = ProductSearchClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductSearchClient.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.ProductSearchTransport, '_prep_wrapped_messages') as prep: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductSearchTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductSearchClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'grpc', + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() From 465e45351e20b87dee0b2c40dffea5fed81fad2c Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 6 Oct 2021 22:56:16 +0000 Subject: [PATCH 2/2] =?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/main/packages/owl-bot/README.md --- .../services/image_annotator/async_client.py | 6 + .../services/image_annotator/client.py | 18 +- .../image_annotator/transports/base.py | 9 + .../image_annotator/transports/grpc.py | 3 + .../transports/grpc_asyncio.py | 3 + .../services/product_search/async_client.py | 6 + .../services/product_search/client.py | 18 +- .../product_search/transports/base.py | 9 + .../product_search/transports/grpc.py | 3 + .../product_search/transports/grpc_asyncio.py | 3 + google/cloud/vision_v1/types/geometry.py | 1 + .../cloud/vision_v1/types/image_annotator.py | 23 + .../cloud/vision_v1/types/product_search.py | 4 + .../vision_v1/types/product_search_service.py | 26 + .../cloud/vision_v1/types/text_annotation.py | 7 + google/cloud/vision_v1/types/web_detection.py | 5 + .../services/image_annotator/async_client.py | 6 + .../services/image_annotator/client.py | 18 +- .../image_annotator/transports/base.py | 9 + .../image_annotator/transports/grpc.py | 3 + .../transports/grpc_asyncio.py | 3 + .../cloud/vision_v1p1beta1/types/geometry.py | 1 + .../vision_v1p1beta1/types/image_annotator.py | 14 + .../vision_v1p1beta1/types/text_annotation.py | 7 + .../vision_v1p1beta1/types/web_detection.py | 5 + .../services/image_annotator/async_client.py | 6 + .../services/image_annotator/client.py | 18 +- .../image_annotator/transports/base.py | 9 + .../image_annotator/transports/grpc.py | 3 + .../transports/grpc_asyncio.py | 3 + .../cloud/vision_v1p2beta1/types/geometry.py | 1 + .../vision_v1p2beta1/types/image_annotator.py | 19 + .../vision_v1p2beta1/types/text_annotation.py | 7 + .../vision_v1p2beta1/types/web_detection.py | 5 + .../services/image_annotator/async_client.py | 6 + .../services/image_annotator/client.py | 18 +- .../image_annotator/transports/base.py | 9 + .../image_annotator/transports/grpc.py | 3 + .../transports/grpc_asyncio.py | 3 + .../services/product_search/async_client.py | 6 + .../services/product_search/client.py | 18 +- .../product_search/transports/base.py | 9 + .../product_search/transports/grpc.py | 3 + .../product_search/transports/grpc_asyncio.py | 3 + .../cloud/vision_v1p3beta1/types/geometry.py | 2 + .../vision_v1p3beta1/types/image_annotator.py | 20 + .../vision_v1p3beta1/types/product_search.py | 4 + .../types/product_search_service.py | 25 + .../vision_v1p3beta1/types/text_annotation.py | 7 + .../vision_v1p3beta1/types/web_detection.py | 5 + .../services/image_annotator/async_client.py | 6 + .../services/image_annotator/client.py | 18 +- .../image_annotator/transports/base.py | 9 + .../image_annotator/transports/grpc.py | 3 + .../transports/grpc_asyncio.py | 3 + .../services/product_search/async_client.py | 6 + .../services/product_search/client.py | 18 +- .../product_search/transports/base.py | 9 + .../product_search/transports/grpc.py | 3 + .../product_search/transports/grpc_asyncio.py | 3 + google/cloud/vision_v1p4beta1/types/face.py | 3 + .../cloud/vision_v1p4beta1/types/geometry.py | 1 + .../vision_v1p4beta1/types/image_annotator.py | 23 + .../vision_v1p4beta1/types/product_search.py | 4 + .../types/product_search_service.py | 26 + .../vision_v1p4beta1/types/text_annotation.py | 7 + .../vision_v1p4beta1/types/web_detection.py | 5 + 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 - owl-bot-staging/v1/docs/index.rst | 7 - .../v1/docs/vision_v1/image_annotator.rst | 6 - .../v1/docs/vision_v1/product_search.rst | 10 - .../v1/docs/vision_v1/services.rst | 7 - owl-bot-staging/v1/docs/vision_v1/types.rst | 7 - .../v1/google/cloud/vision/__init__.py | 195 - .../v1/google/cloud/vision/py.typed | 2 - .../v1/google/cloud/vision_v1/__init__.py | 196 - .../cloud/vision_v1/gapic_metadata.json | 267 - .../v1/google/cloud/vision_v1/py.typed | 2 - .../cloud/vision_v1/services/__init__.py | 15 - .../services/image_annotator/__init__.py | 22 - .../services/image_annotator/async_client.py | 525 -- .../services/image_annotator/client.py | 703 -- .../image_annotator/transports/__init__.py | 33 - .../image_annotator/transports/base.py | 255 - .../image_annotator/transports/grpc.py | 379 - .../transports/grpc_asyncio.py | 384 - .../services/product_search/__init__.py | 22 - .../services/product_search/async_client.py | 2104 ------ .../services/product_search/client.py | 2196 ------ .../services/product_search/pagers.py | 506 -- .../product_search/transports/__init__.py | 33 - .../product_search/transports/base.py | 561 -- .../product_search/transports/grpc.py | 912 --- .../product_search/transports/grpc_asyncio.py | 917 --- .../google/cloud/vision_v1/types/__init__.py | 198 - .../google/cloud/vision_v1/types/geometry.py | 125 - .../cloud/vision_v1/types/image_annotator.py | 1612 ----- .../cloud/vision_v1/types/product_search.py | 222 - .../vision_v1/types/product_search_service.py | 1075 --- .../cloud/vision_v1/types/text_annotation.py | 393 - .../cloud/vision_v1/types/web_detection.py | 201 - owl-bot-staging/v1/mypy.ini | 3 - owl-bot-staging/v1/noxfile.py | 132 - .../v1/scripts/fixup_vision_v1_keywords.py | 198 - owl-bot-staging/v1/setup.py | 54 - owl-bot-staging/v1/tests/__init__.py | 16 - owl-bot-staging/v1/tests/unit/__init__.py | 16 - .../v1/tests/unit/gapic/__init__.py | 16 - .../v1/tests/unit/gapic/vision_v1/__init__.py | 16 - .../gapic/vision_v1/test_image_annotator.py | 1723 ----- .../gapic/vision_v1/test_product_search.py | 6323 ----------------- owl-bot-staging/v1p1beta1/.coveragerc | 17 - owl-bot-staging/v1p1beta1/MANIFEST.in | 2 - owl-bot-staging/v1p1beta1/README.rst | 49 - owl-bot-staging/v1p1beta1/docs/conf.py | 376 - owl-bot-staging/v1p1beta1/docs/index.rst | 7 - .../docs/vision_v1p1beta1/image_annotator.rst | 6 - .../docs/vision_v1p1beta1/services.rst | 6 - .../v1p1beta1/docs/vision_v1p1beta1/types.rst | 7 - .../v1p1beta1/google/cloud/vision/__init__.py | 89 - .../v1p1beta1/google/cloud/vision/py.typed | 2 - .../google/cloud/vision_v1p1beta1/__init__.py | 90 - .../vision_v1p1beta1/gapic_metadata.json | 33 - .../google/cloud/vision_v1p1beta1/py.typed | 2 - .../vision_v1p1beta1/services/__init__.py | 15 - .../services/image_annotator/__init__.py | 22 - .../services/image_annotator/async_client.py | 241 - .../services/image_annotator/client.py | 422 -- .../image_annotator/transports/__init__.py | 33 - .../image_annotator/transports/base.py | 185 - .../image_annotator/transports/grpc.py | 258 - .../transports/grpc_asyncio.py | 263 - .../cloud/vision_v1p1beta1/types/__init__.py | 92 - .../cloud/vision_v1p1beta1/types/geometry.py | 95 - .../vision_v1p1beta1/types/image_annotator.py | 947 --- .../vision_v1p1beta1/types/text_annotation.py | 378 - .../vision_v1p1beta1/types/web_detection.py | 199 - owl-bot-staging/v1p1beta1/mypy.ini | 3 - owl-bot-staging/v1p1beta1/noxfile.py | 132 - .../fixup_vision_v1p1beta1_keywords.py | 176 - owl-bot-staging/v1p1beta1/setup.py | 54 - owl-bot-staging/v1p1beta1/tests/__init__.py | 16 - .../v1p1beta1/tests/unit/__init__.py | 16 - .../v1p1beta1/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/vision_v1p1beta1/__init__.py | 16 - .../vision_v1p1beta1/test_image_annotator.py | 1131 --- owl-bot-staging/v1p2beta1/.coveragerc | 17 - owl-bot-staging/v1p2beta1/MANIFEST.in | 2 - owl-bot-staging/v1p2beta1/README.rst | 49 - owl-bot-staging/v1p2beta1/docs/conf.py | 376 - owl-bot-staging/v1p2beta1/docs/index.rst | 7 - .../docs/vision_v1p2beta1/image_annotator.rst | 6 - .../docs/vision_v1p2beta1/services.rst | 6 - .../v1p2beta1/docs/vision_v1p2beta1/types.rst | 7 - .../v1p2beta1/google/cloud/vision/__init__.py | 113 - .../v1p2beta1/google/cloud/vision/py.typed | 2 - .../google/cloud/vision_v1p2beta1/__init__.py | 114 - .../vision_v1p2beta1/gapic_metadata.json | 43 - .../google/cloud/vision_v1p2beta1/py.typed | 2 - .../vision_v1p2beta1/services/__init__.py | 15 - .../services/image_annotator/__init__.py | 22 - .../services/image_annotator/async_client.py | 334 - .../services/image_annotator/client.py | 508 -- .../image_annotator/transports/__init__.py | 33 - .../image_annotator/transports/base.py | 213 - .../image_annotator/transports/grpc.py | 309 - .../transports/grpc_asyncio.py | 314 - .../cloud/vision_v1p2beta1/types/__init__.py | 116 - .../cloud/vision_v1p2beta1/types/geometry.py | 125 - .../vision_v1p2beta1/types/image_annotator.py | 1256 ---- .../vision_v1p2beta1/types/text_annotation.py | 393 - .../vision_v1p2beta1/types/web_detection.py | 199 - owl-bot-staging/v1p2beta1/mypy.ini | 3 - owl-bot-staging/v1p2beta1/noxfile.py | 132 - .../fixup_vision_v1p2beta1_keywords.py | 177 - owl-bot-staging/v1p2beta1/setup.py | 54 - owl-bot-staging/v1p2beta1/tests/__init__.py | 16 - .../v1p2beta1/tests/unit/__init__.py | 16 - .../v1p2beta1/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/vision_v1p2beta1/__init__.py | 16 - .../vision_v1p2beta1/test_image_annotator.py | 1341 ---- owl-bot-staging/v1p3beta1/.coveragerc | 17 - owl-bot-staging/v1p3beta1/MANIFEST.in | 2 - owl-bot-staging/v1p3beta1/README.rst | 49 - owl-bot-staging/v1p3beta1/docs/conf.py | 376 - owl-bot-staging/v1p3beta1/docs/index.rst | 7 - .../docs/vision_v1p3beta1/image_annotator.rst | 6 - .../docs/vision_v1p3beta1/product_search.rst | 10 - .../docs/vision_v1p3beta1/services.rst | 7 - .../v1p3beta1/docs/vision_v1p3beta1/types.rst | 7 - .../v1p3beta1/google/cloud/vision/__init__.py | 187 - .../v1p3beta1/google/cloud/vision/py.typed | 2 - .../google/cloud/vision_v1p3beta1/__init__.py | 188 - .../vision_v1p3beta1/gapic_metadata.json | 237 - .../google/cloud/vision_v1p3beta1/py.typed | 2 - .../vision_v1p3beta1/services/__init__.py | 15 - .../services/image_annotator/__init__.py | 22 - .../services/image_annotator/async_client.py | 336 - .../services/image_annotator/client.py | 530 -- .../image_annotator/transports/__init__.py | 33 - .../image_annotator/transports/base.py | 211 - .../image_annotator/transports/grpc.py | 309 - .../transports/grpc_asyncio.py | 314 - .../services/product_search/__init__.py | 22 - .../services/product_search/async_client.py | 1988 ------ .../services/product_search/client.py | 2093 ------ .../services/product_search/pagers.py | 506 -- .../product_search/transports/__init__.py | 33 - .../product_search/transports/base.py | 534 -- .../product_search/transports/grpc.py | 880 --- .../product_search/transports/grpc_asyncio.py | 885 --- .../cloud/vision_v1p3beta1/types/__init__.py | 190 - .../cloud/vision_v1p3beta1/types/geometry.py | 141 - .../vision_v1p3beta1/types/image_annotator.py | 1327 ---- .../vision_v1p3beta1/types/product_search.py | 249 - .../types/product_search_service.py | 998 --- .../vision_v1p3beta1/types/text_annotation.py | 393 - .../vision_v1p3beta1/types/web_detection.py | 199 - owl-bot-staging/v1p3beta1/mypy.ini | 3 - owl-bot-staging/v1p3beta1/noxfile.py | 132 - .../fixup_vision_v1p3beta1_keywords.py | 195 - owl-bot-staging/v1p3beta1/setup.py | 54 - owl-bot-staging/v1p3beta1/tests/__init__.py | 16 - .../v1p3beta1/tests/unit/__init__.py | 16 - .../v1p3beta1/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/vision_v1p3beta1/__init__.py | 16 - .../vision_v1p3beta1/test_image_annotator.py | 1385 ---- .../vision_v1p3beta1/test_product_search.py | 6093 ---------------- owl-bot-staging/v1p4beta1/.coveragerc | 17 - owl-bot-staging/v1p4beta1/MANIFEST.in | 2 - owl-bot-staging/v1p4beta1/README.rst | 49 - owl-bot-staging/v1p4beta1/docs/conf.py | 376 - owl-bot-staging/v1p4beta1/docs/index.rst | 7 - .../docs/vision_v1p4beta1/image_annotator.rst | 6 - .../docs/vision_v1p4beta1/product_search.rst | 10 - .../docs/vision_v1p4beta1/services.rst | 7 - .../v1p4beta1/docs/vision_v1p4beta1/types.rst | 7 - .../v1p4beta1/google/cloud/vision/__init__.py | 201 - .../v1p4beta1/google/cloud/vision/py.typed | 2 - .../google/cloud/vision_v1p4beta1/__init__.py | 202 - .../vision_v1p4beta1/gapic_metadata.json | 267 - .../google/cloud/vision_v1p4beta1/py.typed | 2 - .../vision_v1p4beta1/services/__init__.py | 15 - .../services/image_annotator/__init__.py | 22 - .../services/image_annotator/async_client.py | 517 -- .../services/image_annotator/client.py | 703 -- .../image_annotator/transports/__init__.py | 33 - .../image_annotator/transports/base.py | 247 - .../image_annotator/transports/grpc.py | 379 - .../transports/grpc_asyncio.py | 384 - .../services/product_search/__init__.py | 22 - .../services/product_search/async_client.py | 2095 ------ .../services/product_search/client.py | 2200 ------ .../services/product_search/pagers.py | 506 -- .../product_search/transports/__init__.py | 33 - .../product_search/transports/base.py | 548 -- .../product_search/transports/grpc.py | 914 --- .../product_search/transports/grpc_asyncio.py | 919 --- .../cloud/vision_v1p4beta1/types/__init__.py | 206 - .../cloud/vision_v1p4beta1/types/face.py | 97 - .../cloud/vision_v1p4beta1/types/geometry.py | 125 - .../vision_v1p4beta1/types/image_annotator.py | 1518 ---- .../vision_v1p4beta1/types/product_search.py | 222 - .../types/product_search_service.py | 1077 --- .../vision_v1p4beta1/types/text_annotation.py | 393 - .../vision_v1p4beta1/types/web_detection.py | 201 - owl-bot-staging/v1p4beta1/mypy.ini | 3 - owl-bot-staging/v1p4beta1/noxfile.py | 132 - .../fixup_vision_v1p4beta1_keywords.py | 198 - owl-bot-staging/v1p4beta1/setup.py | 54 - owl-bot-staging/v1p4beta1/tests/__init__.py | 16 - .../v1p4beta1/tests/unit/__init__.py | 16 - .../v1p4beta1/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/vision_v1p4beta1/__init__.py | 16 - .../vision_v1p4beta1/test_image_annotator.py | 1724 ----- .../vision_v1p4beta1/test_product_search.py | 6323 ----------------- .../gapic/vision_v1/test_image_annotator.py | 50 + .../gapic/vision_v1/test_product_search.py | 50 + .../vision_v1p1beta1/test_image_annotator.py | 50 + .../vision_v1p2beta1/test_image_annotator.py | 50 + .../vision_v1p3beta1/test_image_annotator.py | 50 + .../vision_v1p3beta1/test_product_search.py | 50 + .../vision_v1p4beta1/test_image_annotator.py | 50 + .../vision_v1p4beta1/test_product_search.py | 50 + 287 files changed, 937 insertions(+), 79073 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/index.rst delete mode 100644 owl-bot-staging/v1/docs/vision_v1/image_annotator.rst delete mode 100644 owl-bot-staging/v1/docs/vision_v1/product_search.rst delete mode 100644 owl-bot-staging/v1/docs/vision_v1/services.rst delete mode 100644 owl-bot-staging/v1/docs/vision_v1/types.rst delete mode 100644 owl-bot-staging/v1/google/cloud/vision/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision/py.typed delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/py.typed delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py delete mode 100644 owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.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_vision_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/vision_v1/__init__.py delete mode 100644 owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_image_annotator.py delete mode 100644 owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py delete mode 100644 owl-bot-staging/v1p1beta1/.coveragerc delete mode 100644 owl-bot-staging/v1p1beta1/MANIFEST.in delete mode 100644 owl-bot-staging/v1p1beta1/README.rst delete mode 100644 owl-bot-staging/v1p1beta1/docs/conf.py delete mode 100644 owl-bot-staging/v1p1beta1/docs/index.rst delete mode 100644 owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst delete mode 100644 owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst delete mode 100644 owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py delete mode 100644 owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py delete mode 100644 owl-bot-staging/v1p1beta1/mypy.ini delete mode 100644 owl-bot-staging/v1p1beta1/noxfile.py delete mode 100644 owl-bot-staging/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py delete mode 100644 owl-bot-staging/v1p1beta1/setup.py delete mode 100644 owl-bot-staging/v1p1beta1/tests/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__init__.py delete mode 100644 owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py delete mode 100644 owl-bot-staging/v1p2beta1/.coveragerc delete mode 100644 owl-bot-staging/v1p2beta1/MANIFEST.in delete mode 100644 owl-bot-staging/v1p2beta1/README.rst delete mode 100644 owl-bot-staging/v1p2beta1/docs/conf.py delete mode 100644 owl-bot-staging/v1p2beta1/docs/index.rst delete mode 100644 owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst delete mode 100644 owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst delete mode 100644 owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/gapic_metadata.json delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py delete mode 100644 owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py delete mode 100644 owl-bot-staging/v1p2beta1/mypy.ini delete mode 100644 owl-bot-staging/v1p2beta1/noxfile.py delete mode 100644 owl-bot-staging/v1p2beta1/scripts/fixup_vision_v1p2beta1_keywords.py delete mode 100644 owl-bot-staging/v1p2beta1/setup.py delete mode 100644 owl-bot-staging/v1p2beta1/tests/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__init__.py delete mode 100644 owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py delete mode 100644 owl-bot-staging/v1p3beta1/.coveragerc delete mode 100644 owl-bot-staging/v1p3beta1/MANIFEST.in delete mode 100644 owl-bot-staging/v1p3beta1/README.rst delete mode 100644 owl-bot-staging/v1p3beta1/docs/conf.py delete mode 100644 owl-bot-staging/v1p3beta1/docs/index.rst delete mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst delete mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst delete mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst delete mode 100644 owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py delete mode 100644 owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py delete mode 100644 owl-bot-staging/v1p3beta1/mypy.ini delete mode 100644 owl-bot-staging/v1p3beta1/noxfile.py delete mode 100644 owl-bot-staging/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py delete mode 100644 owl-bot-staging/v1p3beta1/setup.py delete mode 100644 owl-bot-staging/v1p3beta1/tests/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__init__.py delete mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py delete mode 100644 owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py delete mode 100644 owl-bot-staging/v1p4beta1/.coveragerc delete mode 100644 owl-bot-staging/v1p4beta1/MANIFEST.in delete mode 100644 owl-bot-staging/v1p4beta1/README.rst delete mode 100644 owl-bot-staging/v1p4beta1/docs/conf.py delete mode 100644 owl-bot-staging/v1p4beta1/docs/index.rst delete mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst delete mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst delete mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst delete mode 100644 owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py delete mode 100644 owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py delete mode 100644 owl-bot-staging/v1p4beta1/mypy.ini delete mode 100644 owl-bot-staging/v1p4beta1/noxfile.py delete mode 100644 owl-bot-staging/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py delete mode 100644 owl-bot-staging/v1p4beta1/setup.py delete mode 100644 owl-bot-staging/v1p4beta1/tests/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__init__.py delete mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py delete mode 100644 owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py diff --git a/google/cloud/vision_v1/services/image_annotator/async_client.py b/google/cloud/vision_v1/services/image_annotator/async_client.py index 311d3df4..0bbb1767 100644 --- a/google/cloud/vision_v1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1/services/image_annotator/async_client.py @@ -525,6 +525,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/image_annotator/client.py b/google/cloud/vision_v1/services/image_annotator/client.py index 122c1ed4..27a199d2 100644 --- a/google/cloud/vision_v1/services/image_annotator/client.py +++ b/google/cloud/vision_v1/services/image_annotator/client.py @@ -365,10 +365,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -704,6 +701,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/image_annotator/transports/base.py b/google/cloud/vision_v1/services/image_annotator/transports/base.py index bf88d098..d151cd5a 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/base.py @@ -219,6 +219,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py index 666c5d3c..42f6671c 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/grpc.py @@ -384,5 +384,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py index 930bb66f..17a5d34f 100644 --- a/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py @@ -391,5 +391,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1/services/product_search/async_client.py b/google/cloud/vision_v1/services/product_search/async_client.py index e8c3bdb8..4da3f2ff 100644 --- a/google/cloud/vision_v1/services/product_search/async_client.py +++ b/google/cloud/vision_v1/services/product_search/async_client.py @@ -2080,6 +2080,12 @@ async def purge_products( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/product_search/client.py b/google/cloud/vision_v1/services/product_search/client.py index ece2329b..7169a753 100644 --- a/google/cloud/vision_v1/services/product_search/client.py +++ b/google/cloud/vision_v1/services/product_search/client.py @@ -404,10 +404,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def create_product_set( @@ -2141,6 +2138,19 @@ def purge_products( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1/services/product_search/transports/base.py b/google/cloud/vision_v1/services/product_search/transports/base.py index a6ae5112..4569d29a 100644 --- a/google/cloud/vision_v1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1/services/product_search/transports/base.py @@ -430,6 +430,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc.py b/google/cloud/vision_v1/services/product_search/transports/grpc.py index df926905..f35155a4 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1/services/product_search/transports/grpc.py @@ -951,5 +951,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + self.grpc_channel.close() + __all__ = ("ProductSearchGrpcTransport",) diff --git a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py index 95dcc826..6713950d 100644 --- a/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py @@ -968,5 +968,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ProductSearchGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1/types/geometry.py b/google/cloud/vision_v1/types/geometry.py index c30f0162..47731f18 100644 --- a/google/cloud/vision_v1/types/geometry.py +++ b/google/cloud/vision_v1/types/geometry.py @@ -56,6 +56,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1/types/image_annotator.py b/google/cloud/vision_v1/types/image_annotator.py index 6ae4d5ae..2570e8ca 100644 --- a/google/cloud/vision_v1/types/image_annotator.py +++ b/google/cloud/vision_v1/types/image_annotator.py @@ -164,6 +164,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -242,6 +243,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -317,6 +319,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -327,6 +330,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -343,6 +347,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -398,6 +403,7 @@ class EntityAnnotation(proto.Message): class LocalizedObjectAnnotation(proto.Message): r"""Set of detected objects with bounding boxes. + Attributes: mid (str): Object ID that should align with @@ -484,6 +490,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -516,6 +523,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1.types.ColorInfo]): RGB color values with their score and pixel @@ -527,6 +535,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -573,6 +582,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -590,6 +600,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -615,6 +626,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1.types.LatLongRect): Not used. @@ -694,6 +706,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1.types.FaceAnnotation]): If present, face detection has completed @@ -814,6 +827,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -922,6 +936,7 @@ class BatchAnnotateFilesRequest(proto.Message): class BatchAnnotateFilesResponse(proto.Message): r"""A list of file annotation responses. + Attributes: responses (Sequence[google.cloud.vision_v1.types.AnnotateFileResponse]): The list of file annotation responses, each @@ -937,6 +952,7 @@ class BatchAnnotateFilesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1.types.InputConfig): Required. Information about the input file. @@ -958,6 +974,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1.types.OutputConfig): The output location and metadata from @@ -969,6 +986,7 @@ class AsyncAnnotateFileResponse(proto.Message): class AsyncBatchAnnotateImagesRequest(proto.Message): r"""Request for async image annotation for a list of images. + Attributes: requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): Required. Individual image annotation @@ -1000,6 +1018,7 @@ class AsyncBatchAnnotateImagesRequest(proto.Message): class AsyncBatchAnnotateImagesResponse(proto.Message): r"""Response to an async batch image annotation request. + Attributes: output_config (google.cloud.vision_v1.types.OutputConfig): The output location and metadata from @@ -1040,6 +1059,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -1054,6 +1074,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1.types.GcsSource): The Google Cloud Storage location to read the @@ -1079,6 +1100,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1.types.GcsDestination): The Google Cloud Storage location to write @@ -1154,6 +1176,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1/types/product_search.py b/google/cloud/vision_v1/types/product_search.py index 17364f24..7d09aecd 100644 --- a/google/cloud/vision_v1/types/product_search.py +++ b/google/cloud/vision_v1/types/product_search.py @@ -28,6 +28,7 @@ class ProductSearchParams(proto.Message): r"""Parameters for a product search request. + Attributes: bounding_poly (google.cloud.vision_v1.types.BoundingPoly): The bounding polygon around the area of @@ -74,6 +75,7 @@ class ProductSearchParams(proto.Message): class ProductSearchResults(proto.Message): r"""Results for a product search request. + Attributes: index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these @@ -93,6 +95,7 @@ class ProductSearchResults(proto.Message): class Result(proto.Message): r"""Information about a product. + Attributes: product (google.cloud.vision_v1.types.Product): The Product. @@ -112,6 +115,7 @@ class Result(proto.Message): class ObjectAnnotation(proto.Message): r"""Prediction for what the object in the bounding box is. + Attributes: mid (str): Object ID that should align with diff --git a/google/cloud/vision_v1/types/product_search_service.py b/google/cloud/vision_v1/types/product_search_service.py index 269230e9..d3844e2c 100644 --- a/google/cloud/vision_v1/types/product_search_service.py +++ b/google/cloud/vision_v1/types/product_search_service.py @@ -61,6 +61,7 @@ class Product(proto.Message): r"""A Product contains ReferenceImages. + Attributes: name (str): The resource name of the product. @@ -104,6 +105,7 @@ class Product(proto.Message): class KeyValue(proto.Message): r"""A product label represented as a key-value pair. + Attributes: key (str): The key of the label attached to the product. @@ -204,6 +206,7 @@ class ReferenceImage(proto.Message): class CreateProductRequest(proto.Message): r"""Request message for the ``CreateProduct`` method. + Attributes: parent (str): Required. The project in which the Product should be @@ -227,6 +230,7 @@ class CreateProductRequest(proto.Message): class ListProductsRequest(proto.Message): r"""Request message for the ``ListProducts`` method. + Attributes: parent (str): Required. The project OR ProductSet from which Products @@ -248,6 +252,7 @@ class ListProductsRequest(proto.Message): class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. + Attributes: products (Sequence[google.cloud.vision_v1.types.Product]): List of products. @@ -267,6 +272,7 @@ def raw_page(self): class GetProductRequest(proto.Message): r"""Request message for the ``GetProduct`` method. + Attributes: name (str): Required. Resource name of the Product to get. @@ -280,6 +286,7 @@ class GetProductRequest(proto.Message): class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. + Attributes: product (google.cloud.vision_v1.types.Product): Required. The Product resource which replaces @@ -300,6 +307,7 @@ class UpdateProductRequest(proto.Message): class DeleteProductRequest(proto.Message): r"""Request message for the ``DeleteProduct`` method. + Attributes: name (str): Required. Resource name of product to delete. @@ -313,6 +321,7 @@ class DeleteProductRequest(proto.Message): class CreateProductSetRequest(proto.Message): r"""Request message for the ``CreateProductSet`` method. + Attributes: parent (str): Required. The project in which the ProductSet should be @@ -336,6 +345,7 @@ class CreateProductSetRequest(proto.Message): class ListProductSetsRequest(proto.Message): r"""Request message for the ``ListProductSets`` method. + Attributes: parent (str): Required. The project from which ProductSets should be @@ -357,6 +367,7 @@ class ListProductSetsRequest(proto.Message): class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. + Attributes: product_sets (Sequence[google.cloud.vision_v1.types.ProductSet]): List of ProductSets. @@ -376,6 +387,7 @@ def raw_page(self): class GetProductSetRequest(proto.Message): r"""Request message for the ``GetProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to get. @@ -389,6 +401,7 @@ class GetProductSetRequest(proto.Message): class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. + Attributes: product_set (google.cloud.vision_v1.types.ProductSet): Required. The ProductSet resource which @@ -408,6 +421,7 @@ class UpdateProductSetRequest(proto.Message): class DeleteProductSetRequest(proto.Message): r"""Request message for the ``DeleteProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to delete. @@ -421,6 +435,7 @@ class DeleteProductSetRequest(proto.Message): class CreateReferenceImageRequest(proto.Message): r"""Request message for the ``CreateReferenceImage`` method. + Attributes: parent (str): Required. Resource name of the product in which to create @@ -446,6 +461,7 @@ class CreateReferenceImageRequest(proto.Message): class ListReferenceImagesRequest(proto.Message): r"""Request message for the ``ListReferenceImages`` method. + Attributes: parent (str): Required. Resource name of the product containing the @@ -471,6 +487,7 @@ class ListReferenceImagesRequest(proto.Message): class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. + Attributes: reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): The list of reference images. @@ -495,6 +512,7 @@ def raw_page(self): class GetReferenceImageRequest(proto.Message): r"""Request message for the ``GetReferenceImage`` method. + Attributes: name (str): Required. The resource name of the ReferenceImage to get. @@ -508,6 +526,7 @@ class GetReferenceImageRequest(proto.Message): class DeleteReferenceImageRequest(proto.Message): r"""Request message for the ``DeleteReferenceImage`` method. + Attributes: name (str): Required. The resource name of the reference image to @@ -522,6 +541,7 @@ class DeleteReferenceImageRequest(proto.Message): class AddProductToProductSetRequest(proto.Message): r"""Request message for the ``AddProductToProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -542,6 +562,7 @@ class AddProductToProductSetRequest(proto.Message): class RemoveProductFromProductSetRequest(proto.Message): r"""Request message for the ``RemoveProductFromProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -562,6 +583,7 @@ class RemoveProductFromProductSetRequest(proto.Message): class ListProductsInProductSetRequest(proto.Message): r"""Request message for the ``ListProductsInProductSet`` method. + Attributes: name (str): Required. The ProductSet resource for which to retrieve @@ -584,6 +606,7 @@ class ListProductsInProductSetRequest(proto.Message): class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. + Attributes: products (Sequence[google.cloud.vision_v1.types.Product]): The list of Products. @@ -687,6 +710,7 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + Attributes: gcs_source (google.cloud.vision_v1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv @@ -701,6 +725,7 @@ class ImportProductSetsInputConfig(proto.Message): class ImportProductSetsRequest(proto.Message): r"""Request message for the ``ImportProductSets`` method. + Attributes: parent (str): Required. The project in which the ProductSets should be @@ -796,6 +821,7 @@ class ProductSetPurgeConfig(proto.Message): class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. + Attributes: product_set_purge_config (google.cloud.vision_v1.types.ProductSetPurgeConfig): Specify which ProductSet contains the diff --git a/google/cloud/vision_v1/types/text_annotation.py b/google/cloud/vision_v1/types/text_annotation.py index 224fe7c0..94643170 100644 --- a/google/cloud/vision_v1/types/text_annotation.py +++ b/google/cloud/vision_v1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1/types/web_detection.py b/google/cloud/vision_v1/types/web_detection.py index c629b85a..78bab322 100644 --- a/google/cloud/vision_v1/types/web_detection.py +++ b/google/cloud/vision_v1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -49,6 +50,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -67,6 +69,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -80,6 +83,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -112,6 +116,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py index 57a81899..79c154ff 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py @@ -238,6 +238,12 @@ async def batch_annotate_images( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py index 04025123..c3ec4ee0 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/client.py @@ -331,10 +331,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -406,6 +403,19 @@ def batch_annotate_images( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py index ddf9be8f..60872932 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py @@ -172,6 +172,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def batch_annotate_images( self, diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py index 564c52c2..bdb337c0 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py @@ -258,5 +258,8 @@ def batch_annotate_images( ) return self._stubs["batch_annotate_images"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py index f8b7c01b..b0d0aa31 100644 --- a/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py @@ -261,5 +261,8 @@ def batch_annotate_images( ) return self._stubs["batch_annotate_images"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p1beta1/types/geometry.py b/google/cloud/vision_v1p1beta1/types/geometry.py index bc33ea35..29d617a7 100644 --- a/google/cloud/vision_v1p1beta1/types/geometry.py +++ b/google/cloud/vision_v1p1beta1/types/geometry.py @@ -40,6 +40,7 @@ class Vertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p1beta1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1p1beta1/types/image_annotator.py b/google/cloud/vision_v1p1beta1/types/image_annotator.py index b8196484..a099dbae 100644 --- a/google/cloud/vision_v1p1beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p1beta1/types/image_annotator.py @@ -104,6 +104,7 @@ class Type(proto.Enum): class ImageSource(proto.Message): r"""External image source (Google Cloud Storage image location). + Attributes: gcs_image_uri (str): NOTE: For new code ``image_uri`` below is preferred. Google @@ -132,6 +133,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: as @@ -207,6 +209,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -280,6 +283,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -290,6 +294,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -306,6 +311,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -396,6 +402,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -428,6 +435,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p1beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -439,6 +447,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p1beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -485,6 +494,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -502,6 +512,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -527,6 +538,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p1beta1.types.LatLongRect): lat/long rectangle that specifies the @@ -583,6 +595,7 @@ class AnnotateImageRequest(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation]): If present, face detection has completed @@ -672,6 +685,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageResponse]): Individual responses to image annotation diff --git a/google/cloud/vision_v1p1beta1/types/text_annotation.py b/google/cloud/vision_v1p1beta1/types/text_annotation.py index bc458aca..f7d7c049 100644 --- a/google/cloud/vision_v1p1beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p1beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -126,6 +130,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -207,6 +212,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -240,6 +246,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p1beta1/types/web_detection.py b/google/cloud/vision_v1p1beta1/types/web_detection.py index 664f49bd..d23f94b6 100644 --- a/google/cloud/vision_v1p1beta1/types/web_detection.py +++ b/google/cloud/vision_v1p1beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -47,6 +48,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -65,6 +67,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -78,6 +81,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -110,6 +114,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py index d05d66fd..d952f873 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py @@ -332,6 +332,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py index 15ad8646..5462d846 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/client.py @@ -333,10 +333,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -495,6 +492,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py index 1b035ec6..cd9ee952 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py @@ -189,6 +189,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py index f734a3c3..215ddf00 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py @@ -309,5 +309,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py index c7de2e83..ebab6ad9 100644 --- a/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py @@ -315,5 +315,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p2beta1/types/geometry.py b/google/cloud/vision_v1p2beta1/types/geometry.py index c10c04b2..c441eca2 100644 --- a/google/cloud/vision_v1p2beta1/types/geometry.py +++ b/google/cloud/vision_v1p2beta1/types/geometry.py @@ -56,6 +56,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p2beta1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1p2beta1/types/image_annotator.py b/google/cloud/vision_v1p2beta1/types/image_annotator.py index 935b40af..9761a2e7 100644 --- a/google/cloud/vision_v1p2beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p2beta1/types/image_annotator.py @@ -155,6 +155,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -230,6 +231,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -303,6 +305,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -313,6 +316,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -329,6 +333,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -420,6 +425,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -452,6 +458,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p2beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -463,6 +470,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p2beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -509,6 +517,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -526,6 +535,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -551,6 +561,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p2beta1.types.LatLongRect): Not used. @@ -624,6 +635,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation]): If present, face detection has completed @@ -737,6 +749,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -750,6 +763,7 @@ class BatchAnnotateImagesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1p2beta1.types.InputConfig): Required. Information about the input file. @@ -771,6 +785,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): The output location and metadata from @@ -797,6 +812,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -811,6 +827,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1p2beta1.types.GcsSource): The Google Cloud Storage location to read the @@ -827,6 +844,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1p2beta1.types.GcsDestination): The Google Cloud Storage location to write @@ -893,6 +911,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1p2beta1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1p2beta1/types/text_annotation.py b/google/cloud/vision_v1p2beta1/types/text_annotation.py index c8e457f3..2bd6a914 100644 --- a/google/cloud/vision_v1p2beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p2beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p2beta1/types/web_detection.py b/google/cloud/vision_v1p2beta1/types/web_detection.py index 45f796f7..4ae5075b 100644 --- a/google/cloud/vision_v1p2beta1/types/web_detection.py +++ b/google/cloud/vision_v1p2beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -47,6 +48,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -65,6 +67,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -78,6 +81,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -110,6 +114,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py index 8c460024..1eeba811 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py @@ -333,6 +333,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py index 1ac9894b..30d68db0 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/client.py @@ -365,10 +365,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -527,6 +524,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py index 2d9866fc..4aef3c5e 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py @@ -186,6 +186,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py index f017059c..db3cb8d5 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py @@ -309,5 +309,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py index ad423c81..0114a89c 100644 --- a/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py @@ -315,5 +315,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py index 3ac90b29..f5078491 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/async_client.py @@ -1962,6 +1962,12 @@ async def import_product_sets( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/product_search/client.py b/google/cloud/vision_v1p3beta1/services/product_search/client.py index 0e9e3a23..4ea43f52 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/client.py @@ -405,10 +405,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def create_product_set( @@ -2042,6 +2039,19 @@ def import_product_sets( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py index 3a408858..14afcdb7 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py @@ -406,6 +406,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py index a048c268..5c642bba 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py @@ -917,5 +917,8 @@ def import_product_sets( ) return self._stubs["import_product_sets"] + def close(self): + self.grpc_channel.close() + __all__ = ("ProductSearchGrpcTransport",) diff --git a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py index cd9326a6..83fe6924 100644 --- a/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py @@ -933,5 +933,8 @@ def import_product_sets( ) return self._stubs["import_product_sets"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ProductSearchGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p3beta1/types/geometry.py b/google/cloud/vision_v1p3beta1/types/geometry.py index 04c7a90b..1c5e12e6 100644 --- a/google/cloud/vision_v1p3beta1/types/geometry.py +++ b/google/cloud/vision_v1p3beta1/types/geometry.py @@ -62,6 +62,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p3beta1.types.Vertex]): The bounding polygon vertices. @@ -77,6 +78,7 @@ class BoundingPoly(proto.Message): class NormalizedBoundingPoly(proto.Message): r"""A normalized bounding polygon around a portion of an image. + Attributes: vertices (Sequence[google.cloud.vision_v1p3beta1.types.NormalizedVertex]): Normalized vertices of the bounding polygon. diff --git a/google/cloud/vision_v1p3beta1/types/image_annotator.py b/google/cloud/vision_v1p3beta1/types/image_annotator.py index a0fa0b7c..aad0e4fe 100644 --- a/google/cloud/vision_v1p3beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p3beta1/types/image_annotator.py @@ -159,6 +159,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -234,6 +235,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -307,6 +309,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -317,6 +320,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -333,6 +337,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -388,6 +393,7 @@ class EntityAnnotation(proto.Message): class LocalizedObjectAnnotation(proto.Message): r"""Set of detected objects with bounding boxes. + Attributes: mid (str): Object ID that should align with @@ -450,6 +456,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -482,6 +489,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p3beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -493,6 +501,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p3beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -539,6 +548,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -556,6 +566,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -581,6 +592,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p3beta1.types.LatLongRect): Not used. @@ -659,6 +671,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation]): If present, face detection has completed @@ -785,6 +798,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -798,6 +812,7 @@ class BatchAnnotateImagesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1p3beta1.types.InputConfig): Required. Information about the input file. @@ -819,6 +834,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): The output location and metadata from @@ -845,6 +861,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -859,6 +876,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1p3beta1.types.GcsSource): The Google Cloud Storage location to read the @@ -875,6 +893,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1p3beta1.types.GcsDestination): The Google Cloud Storage location to write @@ -941,6 +960,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1p3beta1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1p3beta1/types/product_search.py b/google/cloud/vision_v1p3beta1/types/product_search.py index f96c5a38..8f565a8c 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search.py +++ b/google/cloud/vision_v1p3beta1/types/product_search.py @@ -46,6 +46,7 @@ class ProductSearchResultsView(proto.Enum): class ProductSearchParams(proto.Message): r"""Parameters for a product search request. + Attributes: catalog_name (str): The resource name of the catalog to search. @@ -109,6 +110,7 @@ class ProductSearchParams(proto.Message): class ProductSearchResults(proto.Message): r"""Results for a product search request. + Attributes: category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): Product category. [Deprecated] Use ``product_category``. @@ -128,6 +130,7 @@ class ProductSearchResults(proto.Message): class ProductInfo(proto.Message): r"""Information about a product. + Attributes: product_id (str): Product ID. @@ -150,6 +153,7 @@ class ProductInfo(proto.Message): class Result(proto.Message): r"""Information about a product. + Attributes: product (google.cloud.vision_v1p3beta1.types.Product): The Product. diff --git a/google/cloud/vision_v1p3beta1/types/product_search_service.py b/google/cloud/vision_v1p3beta1/types/product_search_service.py index c42c3bf1..de561f13 100644 --- a/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p3beta1/types/product_search_service.py @@ -59,6 +59,7 @@ class Product(proto.Message): r"""A Product contains ReferenceImages. + Attributes: name (str): The resource name of the product. @@ -96,6 +97,7 @@ class Product(proto.Message): class KeyValue(proto.Message): r"""A product label represented as a key-value pair. + Attributes: key (str): The key of the label attached to the product. @@ -196,6 +198,7 @@ class ReferenceImage(proto.Message): class CreateProductRequest(proto.Message): r"""Request message for the ``CreateProduct`` method. + Attributes: parent (str): Required. The project in which the Product should be @@ -219,6 +222,7 @@ class CreateProductRequest(proto.Message): class ListProductsRequest(proto.Message): r"""Request message for the ``ListProducts`` method. + Attributes: parent (str): Required. The project OR ProductSet from which Products @@ -240,6 +244,7 @@ class ListProductsRequest(proto.Message): class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. + Attributes: products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): List of products. @@ -259,6 +264,7 @@ def raw_page(self): class GetProductRequest(proto.Message): r"""Request message for the ``GetProduct`` method. + Attributes: name (str): Required. Resource name of the Product to get. @@ -272,6 +278,7 @@ class GetProductRequest(proto.Message): class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. + Attributes: product (google.cloud.vision_v1p3beta1.types.Product): Required. The Product resource which replaces @@ -292,6 +299,7 @@ class UpdateProductRequest(proto.Message): class DeleteProductRequest(proto.Message): r"""Request message for the ``DeleteProduct`` method. + Attributes: name (str): Required. Resource name of product to delete. @@ -305,6 +313,7 @@ class DeleteProductRequest(proto.Message): class CreateProductSetRequest(proto.Message): r"""Request message for the ``CreateProductSet`` method. + Attributes: parent (str): Required. The project in which the ProductSet should be @@ -328,6 +337,7 @@ class CreateProductSetRequest(proto.Message): class ListProductSetsRequest(proto.Message): r"""Request message for the ``ListProductSets`` method. + Attributes: parent (str): Required. The project from which ProductSets should be @@ -349,6 +359,7 @@ class ListProductSetsRequest(proto.Message): class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. + Attributes: product_sets (Sequence[google.cloud.vision_v1p3beta1.types.ProductSet]): List of ProductSets. @@ -368,6 +379,7 @@ def raw_page(self): class GetProductSetRequest(proto.Message): r"""Request message for the ``GetProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to get. @@ -381,6 +393,7 @@ class GetProductSetRequest(proto.Message): class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. + Attributes: product_set (google.cloud.vision_v1p3beta1.types.ProductSet): Required. The ProductSet resource which @@ -400,6 +413,7 @@ class UpdateProductSetRequest(proto.Message): class DeleteProductSetRequest(proto.Message): r"""Request message for the ``DeleteProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to delete. @@ -413,6 +427,7 @@ class DeleteProductSetRequest(proto.Message): class CreateReferenceImageRequest(proto.Message): r"""Request message for the ``CreateReferenceImage`` method. + Attributes: parent (str): Required. Resource name of the product in which to create @@ -438,6 +453,7 @@ class CreateReferenceImageRequest(proto.Message): class ListReferenceImagesRequest(proto.Message): r"""Request message for the ``ListReferenceImages`` method. + Attributes: parent (str): Required. Resource name of the product containing the @@ -463,6 +479,7 @@ class ListReferenceImagesRequest(proto.Message): class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. + Attributes: reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): The list of reference images. @@ -487,6 +504,7 @@ def raw_page(self): class GetReferenceImageRequest(proto.Message): r"""Request message for the ``GetReferenceImage`` method. + Attributes: name (str): Required. The resource name of the ReferenceImage to get. @@ -501,6 +519,7 @@ class GetReferenceImageRequest(proto.Message): class DeleteReferenceImageRequest(proto.Message): r"""Request message for the ``DeleteReferenceImage`` method. + Attributes: name (str): Required. The resource name of the reference image to @@ -516,6 +535,7 @@ class DeleteReferenceImageRequest(proto.Message): class AddProductToProductSetRequest(proto.Message): r"""Request message for the ``AddProductToProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -536,6 +556,7 @@ class AddProductToProductSetRequest(proto.Message): class RemoveProductFromProductSetRequest(proto.Message): r"""Request message for the ``RemoveProductFromProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -556,6 +577,7 @@ class RemoveProductFromProductSetRequest(proto.Message): class ListProductsInProductSetRequest(proto.Message): r"""Request message for the ``ListProductsInProductSet`` method. + Attributes: name (str): Required. The ProductSet resource for which to retrieve @@ -578,6 +600,7 @@ class ListProductsInProductSetRequest(proto.Message): class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. + Attributes: products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): The list of Products. @@ -668,6 +691,7 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + Attributes: gcs_source (google.cloud.vision_v1p3beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv @@ -682,6 +706,7 @@ class ImportProductSetsInputConfig(proto.Message): class ImportProductSetsRequest(proto.Message): r"""Request message for the ``ImportProductSets`` method. + Attributes: parent (str): Required. The project in which the ProductSets should be diff --git a/google/cloud/vision_v1p3beta1/types/text_annotation.py b/google/cloud/vision_v1p3beta1/types/text_annotation.py index 8c64ea1f..89dbaea4 100644 --- a/google/cloud/vision_v1p3beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p3beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p3beta1/types/web_detection.py b/google/cloud/vision_v1p3beta1/types/web_detection.py index 608f78aa..5cd68aa4 100644 --- a/google/cloud/vision_v1p3beta1/types/web_detection.py +++ b/google/cloud/vision_v1p3beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -47,6 +48,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -65,6 +67,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -78,6 +81,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -110,6 +114,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py index 37e9e7cd..abb4106e 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py @@ -513,6 +513,12 @@ async def async_batch_annotate_files( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py index c55a79e6..758f47c9 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/client.py @@ -365,10 +365,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def batch_annotate_images( @@ -704,6 +701,19 @@ def async_batch_annotate_files( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py index 77795b1e..b077e031 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py @@ -207,6 +207,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py index 2552c528..53c1ab22 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py @@ -384,5 +384,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcTransport",) diff --git a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py index e9a08482..41428155 100644 --- a/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py @@ -391,5 +391,8 @@ def async_batch_annotate_files( ) return self._stubs["async_batch_annotate_files"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ImageAnnotatorGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py index 2115e0e1..cc062587 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/async_client.py @@ -2065,6 +2065,12 @@ async def purge_products( # Done; return the response. return response + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/product_search/client.py b/google/cloud/vision_v1p4beta1/services/product_search/client.py index d49f5449..8ed9fa46 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/client.py @@ -406,10 +406,7 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, - always_use_jwt_access=( - Transport == type(self).get_transport_class("grpc") - or Transport == type(self).get_transport_class("grpc_asyncio") - ), + always_use_jwt_access=True, ) def create_product_set( @@ -2145,6 +2142,19 @@ def purge_products( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py index 306075e1..e63d65ac 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py @@ -409,6 +409,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py index 2d593894..9f96f612 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py @@ -953,5 +953,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + self.grpc_channel.close() + __all__ = ("ProductSearchGrpcTransport",) diff --git a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py index 78cb7f81..266cf36e 100644 --- a/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ b/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py @@ -970,5 +970,8 @@ def purge_products( ) return self._stubs["purge_products"] + def close(self): + return self.grpc_channel.close() + __all__ = ("ProductSearchGrpcAsyncIOTransport",) diff --git a/google/cloud/vision_v1p4beta1/types/face.py b/google/cloud/vision_v1p4beta1/types/face.py index 4586f25d..99b113f0 100644 --- a/google/cloud/vision_v1p4beta1/types/face.py +++ b/google/cloud/vision_v1p4beta1/types/face.py @@ -24,6 +24,7 @@ class FaceRecognitionParams(proto.Message): r"""Parameters for a celebrity recognition request. + Attributes: celebrity_set (Sequence[str]): The resource names for one or more @@ -39,6 +40,7 @@ class FaceRecognitionParams(proto.Message): class Celebrity(proto.Message): r"""A Celebrity is a group of Faces with an identity. + Attributes: name (str): The resource name of the preloaded Celebrity. Has the format @@ -56,6 +58,7 @@ class Celebrity(proto.Message): class FaceRecognitionResult(proto.Message): r"""Information about a face's identity. + Attributes: celebrity (google.cloud.vision_v1p4beta1.types.Celebrity): The [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] diff --git a/google/cloud/vision_v1p4beta1/types/geometry.py b/google/cloud/vision_v1p4beta1/types/geometry.py index 87fc605d..ecb31d83 100644 --- a/google/cloud/vision_v1p4beta1/types/geometry.py +++ b/google/cloud/vision_v1p4beta1/types/geometry.py @@ -56,6 +56,7 @@ class NormalizedVertex(proto.Message): class BoundingPoly(proto.Message): r"""A bounding polygon for the detected image annotation. + Attributes: vertices (Sequence[google.cloud.vision_v1p4beta1.types.Vertex]): The bounding polygon vertices. diff --git a/google/cloud/vision_v1p4beta1/types/image_annotator.py b/google/cloud/vision_v1p4beta1/types/image_annotator.py index 99e6c7b4..10d51a78 100644 --- a/google/cloud/vision_v1p4beta1/types/image_annotator.py +++ b/google/cloud/vision_v1p4beta1/types/image_annotator.py @@ -165,6 +165,7 @@ class ImageSource(proto.Message): class Image(proto.Message): r"""Client image to perform Google Cloud Vision API tasks over. + Attributes: content (bytes): Image content, represented as a stream of bytes. Note: As @@ -248,6 +249,7 @@ class FaceAnnotation(proto.Message): class Landmark(proto.Message): r"""A face-specific landmark (for example, a face feature). + Attributes: type_ (google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark.Type): Face landmark type. @@ -324,6 +326,7 @@ class Type(proto.Enum): class LocationInfo(proto.Message): r"""Detected entity location information. + Attributes: lat_lng (google.type.latlng_pb2.LatLng): lat/long location coordinates. @@ -334,6 +337,7 @@ class LocationInfo(proto.Message): class Property(proto.Message): r"""A ``Property`` consists of a user-supplied name/value pair. + Attributes: name (str): Name of the property. @@ -350,6 +354,7 @@ class Property(proto.Message): class EntityAnnotation(proto.Message): r"""Set of detected entity features. + Attributes: mid (str): Opaque entity ID. Some IDs may be available in `Google @@ -405,6 +410,7 @@ class EntityAnnotation(proto.Message): class LocalizedObjectAnnotation(proto.Message): r"""Set of detected objects with bounding boxes. + Attributes: mid (str): Object ID that should align with @@ -467,6 +473,7 @@ class SafeSearchAnnotation(proto.Message): class LatLongRect(proto.Message): r"""Rectangle determined by min and max ``LatLng`` pairs. + Attributes: min_lat_lng (google.type.latlng_pb2.LatLng): Min lat/long pair. @@ -499,6 +506,7 @@ class ColorInfo(proto.Message): class DominantColorsAnnotation(proto.Message): r"""Set of dominant colors and their corresponding scores. + Attributes: colors (Sequence[google.cloud.vision_v1p4beta1.types.ColorInfo]): RGB color values with their score and pixel @@ -510,6 +518,7 @@ class DominantColorsAnnotation(proto.Message): class ImageProperties(proto.Message): r"""Stores image properties, such as dominant colors. + Attributes: dominant_colors (google.cloud.vision_v1p4beta1.types.DominantColorsAnnotation): If present, dominant colors completed @@ -556,6 +565,7 @@ class CropHintsAnnotation(proto.Message): class CropHintsParams(proto.Message): r"""Parameters for crop hints annotation request. + Attributes: aspect_ratios (Sequence[float]): Aspect ratios in floats, representing the @@ -573,6 +583,7 @@ class CropHintsParams(proto.Message): class WebDetectionParams(proto.Message): r"""Parameters for web detection request. + Attributes: include_geo_results (bool): Whether to include results derived from the @@ -598,6 +609,7 @@ class TextDetectionParams(proto.Message): class ImageContext(proto.Message): r"""Image context and/or feature-specific parameters. + Attributes: lat_long_rect (google.cloud.vision_v1p4beta1.types.LatLongRect): Not used. @@ -682,6 +694,7 @@ class ImageAnnotationContext(proto.Message): class AnnotateImageResponse(proto.Message): r"""Response to an image annotation request. + Attributes: face_annotations (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation]): If present, face detection has completed @@ -788,6 +801,7 @@ class BatchAnnotateImagesRequest(proto.Message): class BatchAnnotateImagesResponse(proto.Message): r"""Response to a batch image annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): Individual responses to image annotation @@ -882,6 +896,7 @@ class BatchAnnotateFilesRequest(proto.Message): class BatchAnnotateFilesResponse(proto.Message): r"""A list of file annotation responses. + Attributes: responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileResponse]): The list of file annotation responses, each @@ -897,6 +912,7 @@ class BatchAnnotateFilesResponse(proto.Message): class AsyncAnnotateFileRequest(proto.Message): r"""An offline file annotation request. + Attributes: input_config (google.cloud.vision_v1p4beta1.types.InputConfig): Required. Information about the input file. @@ -918,6 +934,7 @@ class AsyncAnnotateFileRequest(proto.Message): class AsyncAnnotateFileResponse(proto.Message): r"""The response for a single offline file annotation request. + Attributes: output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): The output location and metadata from @@ -929,6 +946,7 @@ class AsyncAnnotateFileResponse(proto.Message): class AsyncBatchAnnotateImagesRequest(proto.Message): r"""Request for async image annotation for a list of images. + Attributes: requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): Required. Individual image annotation @@ -946,6 +964,7 @@ class AsyncBatchAnnotateImagesRequest(proto.Message): class AsyncBatchAnnotateImagesResponse(proto.Message): r"""Response to an async batch image annotation request. + Attributes: output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): The output location and metadata from @@ -972,6 +991,7 @@ class AsyncBatchAnnotateFilesRequest(proto.Message): class AsyncBatchAnnotateFilesResponse(proto.Message): r"""Response to an async batch file annotation request. + Attributes: responses (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileResponse]): The list of file annotation responses, one @@ -986,6 +1006,7 @@ class AsyncBatchAnnotateFilesResponse(proto.Message): class InputConfig(proto.Message): r"""The desired input location and metadata. + Attributes: gcs_source (google.cloud.vision_v1p4beta1.types.GcsSource): The Google Cloud Storage location to read the @@ -1011,6 +1032,7 @@ class InputConfig(proto.Message): class OutputConfig(proto.Message): r"""The desired output location and metadata. + Attributes: gcs_destination (google.cloud.vision_v1p4beta1.types.GcsDestination): The Google Cloud Storage location to write @@ -1086,6 +1108,7 @@ class GcsDestination(proto.Message): class OperationMetadata(proto.Message): r"""Contains metadata for the BatchAnnotateImages operation. + Attributes: state (google.cloud.vision_v1p4beta1.types.OperationMetadata.State): Current state of the batch operation. diff --git a/google/cloud/vision_v1p4beta1/types/product_search.py b/google/cloud/vision_v1p4beta1/types/product_search.py index b69426bf..08065000 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search.py +++ b/google/cloud/vision_v1p4beta1/types/product_search.py @@ -28,6 +28,7 @@ class ProductSearchParams(proto.Message): r"""Parameters for a product search request. + Attributes: bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): The bounding polygon around the area of @@ -74,6 +75,7 @@ class ProductSearchParams(proto.Message): class ProductSearchResults(proto.Message): r"""Results for a product search request. + Attributes: index_time (google.protobuf.timestamp_pb2.Timestamp): Timestamp of the index which provided these @@ -93,6 +95,7 @@ class ProductSearchResults(proto.Message): class Result(proto.Message): r"""Information about a product. + Attributes: product (google.cloud.vision_v1p4beta1.types.Product): The Product. @@ -112,6 +115,7 @@ class Result(proto.Message): class ObjectAnnotation(proto.Message): r"""Prediction for what the object in the bounding box is. + Attributes: mid (str): Object ID that should align with diff --git a/google/cloud/vision_v1p4beta1/types/product_search_service.py b/google/cloud/vision_v1p4beta1/types/product_search_service.py index 28dc7191..31c39977 100644 --- a/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ b/google/cloud/vision_v1p4beta1/types/product_search_service.py @@ -61,6 +61,7 @@ class Product(proto.Message): r"""A Product contains ReferenceImages. + Attributes: name (str): The resource name of the product. @@ -103,6 +104,7 @@ class Product(proto.Message): class KeyValue(proto.Message): r"""A product label represented as a key-value pair. + Attributes: key (str): The key of the label attached to the product. @@ -204,6 +206,7 @@ class ReferenceImage(proto.Message): class CreateProductRequest(proto.Message): r"""Request message for the ``CreateProduct`` method. + Attributes: parent (str): Required. The project in which the Product should be @@ -227,6 +230,7 @@ class CreateProductRequest(proto.Message): class ListProductsRequest(proto.Message): r"""Request message for the ``ListProducts`` method. + Attributes: parent (str): Required. The project OR ProductSet from which Products @@ -248,6 +252,7 @@ class ListProductsRequest(proto.Message): class ListProductsResponse(proto.Message): r"""Response message for the ``ListProducts`` method. + Attributes: products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): List of products. @@ -267,6 +272,7 @@ def raw_page(self): class GetProductRequest(proto.Message): r"""Request message for the ``GetProduct`` method. + Attributes: name (str): Required. Resource name of the Product to get. @@ -280,6 +286,7 @@ class GetProductRequest(proto.Message): class UpdateProductRequest(proto.Message): r"""Request message for the ``UpdateProduct`` method. + Attributes: product (google.cloud.vision_v1p4beta1.types.Product): Required. The Product resource which replaces @@ -300,6 +307,7 @@ class UpdateProductRequest(proto.Message): class DeleteProductRequest(proto.Message): r"""Request message for the ``DeleteProduct`` method. + Attributes: name (str): Required. Resource name of product to delete. @@ -313,6 +321,7 @@ class DeleteProductRequest(proto.Message): class CreateProductSetRequest(proto.Message): r"""Request message for the ``CreateProductSet`` method. + Attributes: parent (str): Required. The project in which the ProductSet should be @@ -336,6 +345,7 @@ class CreateProductSetRequest(proto.Message): class ListProductSetsRequest(proto.Message): r"""Request message for the ``ListProductSets`` method. + Attributes: parent (str): Required. The project from which ProductSets should be @@ -357,6 +367,7 @@ class ListProductSetsRequest(proto.Message): class ListProductSetsResponse(proto.Message): r"""Response message for the ``ListProductSets`` method. + Attributes: product_sets (Sequence[google.cloud.vision_v1p4beta1.types.ProductSet]): List of ProductSets. @@ -376,6 +387,7 @@ def raw_page(self): class GetProductSetRequest(proto.Message): r"""Request message for the ``GetProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to get. @@ -389,6 +401,7 @@ class GetProductSetRequest(proto.Message): class UpdateProductSetRequest(proto.Message): r"""Request message for the ``UpdateProductSet`` method. + Attributes: product_set (google.cloud.vision_v1p4beta1.types.ProductSet): Required. The ProductSet resource which @@ -408,6 +421,7 @@ class UpdateProductSetRequest(proto.Message): class DeleteProductSetRequest(proto.Message): r"""Request message for the ``DeleteProductSet`` method. + Attributes: name (str): Required. Resource name of the ProductSet to delete. @@ -421,6 +435,7 @@ class DeleteProductSetRequest(proto.Message): class CreateReferenceImageRequest(proto.Message): r"""Request message for the ``CreateReferenceImage`` method. + Attributes: parent (str): Required. Resource name of the product in which to create @@ -446,6 +461,7 @@ class CreateReferenceImageRequest(proto.Message): class ListReferenceImagesRequest(proto.Message): r"""Request message for the ``ListReferenceImages`` method. + Attributes: parent (str): Required. Resource name of the product containing the @@ -471,6 +487,7 @@ class ListReferenceImagesRequest(proto.Message): class ListReferenceImagesResponse(proto.Message): r"""Response message for the ``ListReferenceImages`` method. + Attributes: reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): The list of reference images. @@ -495,6 +512,7 @@ def raw_page(self): class GetReferenceImageRequest(proto.Message): r"""Request message for the ``GetReferenceImage`` method. + Attributes: name (str): Required. The resource name of the ReferenceImage to get. @@ -509,6 +527,7 @@ class GetReferenceImageRequest(proto.Message): class DeleteReferenceImageRequest(proto.Message): r"""Request message for the ``DeleteReferenceImage`` method. + Attributes: name (str): Required. The resource name of the reference image to @@ -524,6 +543,7 @@ class DeleteReferenceImageRequest(proto.Message): class AddProductToProductSetRequest(proto.Message): r"""Request message for the ``AddProductToProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -544,6 +564,7 @@ class AddProductToProductSetRequest(proto.Message): class RemoveProductFromProductSetRequest(proto.Message): r"""Request message for the ``RemoveProductFromProductSet`` method. + Attributes: name (str): Required. The resource name for the ProductSet to modify. @@ -564,6 +585,7 @@ class RemoveProductFromProductSetRequest(proto.Message): class ListProductsInProductSetRequest(proto.Message): r"""Request message for the ``ListProductsInProductSet`` method. + Attributes: name (str): Required. The ProductSet resource for which to retrieve @@ -586,6 +608,7 @@ class ListProductsInProductSetRequest(proto.Message): class ListProductsInProductSetResponse(proto.Message): r"""Response message for the ``ListProductsInProductSet`` method. + Attributes: products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): The list of Products. @@ -689,6 +712,7 @@ class ImportProductSetsGcsSource(proto.Message): class ImportProductSetsInputConfig(proto.Message): r"""The input content for the ``ImportProductSets`` method. + Attributes: gcs_source (google.cloud.vision_v1p4beta1.types.ImportProductSetsGcsSource): The Google Cloud Storage location for a csv @@ -703,6 +727,7 @@ class ImportProductSetsInputConfig(proto.Message): class ImportProductSetsRequest(proto.Message): r"""Request message for the ``ImportProductSets`` method. + Attributes: parent (str): Required. The project in which the ProductSets should be @@ -798,6 +823,7 @@ class ProductSetPurgeConfig(proto.Message): class PurgeProductsRequest(proto.Message): r"""Request message for the ``PurgeProducts`` method. + Attributes: product_set_purge_config (google.cloud.vision_v1p4beta1.types.ProductSetPurgeConfig): Specify which ProductSet contains the diff --git a/google/cloud/vision_v1p4beta1/types/text_annotation.py b/google/cloud/vision_v1p4beta1/types/text_annotation.py index 4fa23fa0..699c7111 100644 --- a/google/cloud/vision_v1p4beta1/types/text_annotation.py +++ b/google/cloud/vision_v1p4beta1/types/text_annotation.py @@ -43,6 +43,7 @@ class TextAnnotation(proto.Message): class DetectedLanguage(proto.Message): r"""Detected language for a structural component. + Attributes: language_code (str): The BCP-47 language code, such as "en-US" or "sr-Latn". For @@ -57,6 +58,7 @@ class DetectedLanguage(proto.Message): class DetectedBreak(proto.Message): r"""Detected start or end of a structural component. + Attributes: type_ (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak.BreakType): Detected break type. @@ -80,6 +82,7 @@ class BreakType(proto.Enum): class TextProperty(proto.Message): r"""Additional information detected on the structural component. + Attributes: detected_languages (Sequence[google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedLanguage]): A list of detected languages together with @@ -101,6 +104,7 @@ class TextProperty(proto.Message): class Page(proto.Message): r"""Detected page from OCR. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected on the page. @@ -128,6 +132,7 @@ class Page(proto.Message): class Block(proto.Message): r"""Logical element on the page. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the @@ -222,6 +227,7 @@ class Paragraph(proto.Message): class Word(proto.Message): r"""A word representation. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the word. @@ -255,6 +261,7 @@ class Word(proto.Message): class Symbol(proto.Message): r"""A single symbol representation. + Attributes: property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): Additional information detected for the diff --git a/google/cloud/vision_v1p4beta1/types/web_detection.py b/google/cloud/vision_v1p4beta1/types/web_detection.py index b843b5da..a1ecc0b2 100644 --- a/google/cloud/vision_v1p4beta1/types/web_detection.py +++ b/google/cloud/vision_v1p4beta1/types/web_detection.py @@ -23,6 +23,7 @@ class WebDetection(proto.Message): r"""Relevant information for the image from the Internet. + Attributes: web_entities (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebEntity]): Deduced entities from similar images on the @@ -49,6 +50,7 @@ class WebDetection(proto.Message): class WebEntity(proto.Message): r"""Entity deduced from similar images on the Internet. + Attributes: entity_id (str): Opaque entity ID. @@ -67,6 +69,7 @@ class WebEntity(proto.Message): class WebImage(proto.Message): r"""Metadata for online images. + Attributes: url (str): The result image URL. @@ -80,6 +83,7 @@ class WebImage(proto.Message): class WebPage(proto.Message): r"""Metadata for web pages. + Attributes: url (str): The result web page URL. @@ -112,6 +116,7 @@ class WebPage(proto.Message): class WebLabel(proto.Message): r"""Label to provide extra metadata for the web detection. + Attributes: label (str): Label for extra metadata. diff --git a/owl-bot-staging/v1/.coveragerc b/owl-bot-staging/v1/.coveragerc deleted file mode 100644 index 75747063..00000000 --- a/owl-bot-staging/v1/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/vision/__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 67aa21f9..00000000 --- a/owl-bot-staging/v1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/vision *.py -recursive-include google/cloud/vision_v1 *.py diff --git a/owl-bot-staging/v1/README.rst b/owl-bot-staging/v1/README.rst deleted file mode 100644 index 39f9ca72..00000000 --- a/owl-bot-staging/v1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Vision 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 Vision 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 6e730bf5..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-vision 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-vision" -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-vision-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-vision.tex", - u"google-cloud-vision 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-vision", - u"Google Cloud Vision 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-vision", - u"google-cloud-vision Documentation", - author, - "google-cloud-vision", - "GAPIC library for Google Cloud Vision 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/index.rst b/owl-bot-staging/v1/docs/index.rst deleted file mode 100644 index 84760df1..00000000 --- a/owl-bot-staging/v1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - vision_v1/services - vision_v1/types diff --git a/owl-bot-staging/v1/docs/vision_v1/image_annotator.rst b/owl-bot-staging/v1/docs/vision_v1/image_annotator.rst deleted file mode 100644 index 83130a76..00000000 --- a/owl-bot-staging/v1/docs/vision_v1/image_annotator.rst +++ /dev/null @@ -1,6 +0,0 @@ -ImageAnnotator --------------------------------- - -.. automodule:: google.cloud.vision_v1.services.image_annotator - :members: - :inherited-members: diff --git a/owl-bot-staging/v1/docs/vision_v1/product_search.rst b/owl-bot-staging/v1/docs/vision_v1/product_search.rst deleted file mode 100644 index 96f1c798..00000000 --- a/owl-bot-staging/v1/docs/vision_v1/product_search.rst +++ /dev/null @@ -1,10 +0,0 @@ -ProductSearch -------------------------------- - -.. automodule:: google.cloud.vision_v1.services.product_search - :members: - :inherited-members: - -.. automodule:: google.cloud.vision_v1.services.product_search.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/v1/docs/vision_v1/services.rst b/owl-bot-staging/v1/docs/vision_v1/services.rst deleted file mode 100644 index 5fe11bc5..00000000 --- a/owl-bot-staging/v1/docs/vision_v1/services.rst +++ /dev/null @@ -1,7 +0,0 @@ -Services for Google Cloud Vision v1 API -======================================= -.. toctree:: - :maxdepth: 2 - - image_annotator - product_search diff --git a/owl-bot-staging/v1/docs/vision_v1/types.rst b/owl-bot-staging/v1/docs/vision_v1/types.rst deleted file mode 100644 index 52d9869b..00000000 --- a/owl-bot-staging/v1/docs/vision_v1/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Vision v1 API -==================================== - -.. automodule:: google.cloud.vision_v1.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1/google/cloud/vision/__init__.py b/owl-bot-staging/v1/google/cloud/vision/__init__.py deleted file mode 100644 index 8d08cd2c..00000000 --- a/owl-bot-staging/v1/google/cloud/vision/__init__.py +++ /dev/null @@ -1,195 +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.vision_v1.services.image_annotator.client import ImageAnnotatorClient -from google.cloud.vision_v1.services.image_annotator.async_client import ImageAnnotatorAsyncClient -from google.cloud.vision_v1.services.product_search.client import ProductSearchClient -from google.cloud.vision_v1.services.product_search.async_client import ProductSearchAsyncClient - -from google.cloud.vision_v1.types.geometry import BoundingPoly -from google.cloud.vision_v1.types.geometry import NormalizedVertex -from google.cloud.vision_v1.types.geometry import Position -from google.cloud.vision_v1.types.geometry import Vertex -from google.cloud.vision_v1.types.image_annotator import AnnotateFileRequest -from google.cloud.vision_v1.types.image_annotator import AnnotateFileResponse -from google.cloud.vision_v1.types.image_annotator import AnnotateImageRequest -from google.cloud.vision_v1.types.image_annotator import AnnotateImageResponse -from google.cloud.vision_v1.types.image_annotator import AsyncAnnotateFileRequest -from google.cloud.vision_v1.types.image_annotator import AsyncAnnotateFileResponse -from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateFilesRequest -from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateFilesResponse -from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateImagesRequest -from google.cloud.vision_v1.types.image_annotator import AsyncBatchAnnotateImagesResponse -from google.cloud.vision_v1.types.image_annotator import BatchAnnotateFilesRequest -from google.cloud.vision_v1.types.image_annotator import BatchAnnotateFilesResponse -from google.cloud.vision_v1.types.image_annotator import BatchAnnotateImagesRequest -from google.cloud.vision_v1.types.image_annotator import BatchAnnotateImagesResponse -from google.cloud.vision_v1.types.image_annotator import ColorInfo -from google.cloud.vision_v1.types.image_annotator import CropHint -from google.cloud.vision_v1.types.image_annotator import CropHintsAnnotation -from google.cloud.vision_v1.types.image_annotator import CropHintsParams -from google.cloud.vision_v1.types.image_annotator import DominantColorsAnnotation -from google.cloud.vision_v1.types.image_annotator import EntityAnnotation -from google.cloud.vision_v1.types.image_annotator import FaceAnnotation -from google.cloud.vision_v1.types.image_annotator import Feature -from google.cloud.vision_v1.types.image_annotator import GcsDestination -from google.cloud.vision_v1.types.image_annotator import GcsSource -from google.cloud.vision_v1.types.image_annotator import Image -from google.cloud.vision_v1.types.image_annotator import ImageAnnotationContext -from google.cloud.vision_v1.types.image_annotator import ImageContext -from google.cloud.vision_v1.types.image_annotator import ImageProperties -from google.cloud.vision_v1.types.image_annotator import ImageSource -from google.cloud.vision_v1.types.image_annotator import InputConfig -from google.cloud.vision_v1.types.image_annotator import LatLongRect -from google.cloud.vision_v1.types.image_annotator import LocalizedObjectAnnotation -from google.cloud.vision_v1.types.image_annotator import LocationInfo -from google.cloud.vision_v1.types.image_annotator import OperationMetadata -from google.cloud.vision_v1.types.image_annotator import OutputConfig -from google.cloud.vision_v1.types.image_annotator import Property -from google.cloud.vision_v1.types.image_annotator import SafeSearchAnnotation -from google.cloud.vision_v1.types.image_annotator import TextDetectionParams -from google.cloud.vision_v1.types.image_annotator import WebDetectionParams -from google.cloud.vision_v1.types.image_annotator import Likelihood -from google.cloud.vision_v1.types.product_search import ProductSearchParams -from google.cloud.vision_v1.types.product_search import ProductSearchResults -from google.cloud.vision_v1.types.product_search_service import AddProductToProductSetRequest -from google.cloud.vision_v1.types.product_search_service import BatchOperationMetadata -from google.cloud.vision_v1.types.product_search_service import CreateProductRequest -from google.cloud.vision_v1.types.product_search_service import CreateProductSetRequest -from google.cloud.vision_v1.types.product_search_service import CreateReferenceImageRequest -from google.cloud.vision_v1.types.product_search_service import DeleteProductRequest -from google.cloud.vision_v1.types.product_search_service import DeleteProductSetRequest -from google.cloud.vision_v1.types.product_search_service import DeleteReferenceImageRequest -from google.cloud.vision_v1.types.product_search_service import GetProductRequest -from google.cloud.vision_v1.types.product_search_service import GetProductSetRequest -from google.cloud.vision_v1.types.product_search_service import GetReferenceImageRequest -from google.cloud.vision_v1.types.product_search_service import ImportProductSetsGcsSource -from google.cloud.vision_v1.types.product_search_service import ImportProductSetsInputConfig -from google.cloud.vision_v1.types.product_search_service import ImportProductSetsRequest -from google.cloud.vision_v1.types.product_search_service import ImportProductSetsResponse -from google.cloud.vision_v1.types.product_search_service import ListProductSetsRequest -from google.cloud.vision_v1.types.product_search_service import ListProductSetsResponse -from google.cloud.vision_v1.types.product_search_service import ListProductsInProductSetRequest -from google.cloud.vision_v1.types.product_search_service import ListProductsInProductSetResponse -from google.cloud.vision_v1.types.product_search_service import ListProductsRequest -from google.cloud.vision_v1.types.product_search_service import ListProductsResponse -from google.cloud.vision_v1.types.product_search_service import ListReferenceImagesRequest -from google.cloud.vision_v1.types.product_search_service import ListReferenceImagesResponse -from google.cloud.vision_v1.types.product_search_service import Product -from google.cloud.vision_v1.types.product_search_service import ProductSet -from google.cloud.vision_v1.types.product_search_service import ProductSetPurgeConfig -from google.cloud.vision_v1.types.product_search_service import PurgeProductsRequest -from google.cloud.vision_v1.types.product_search_service import ReferenceImage -from google.cloud.vision_v1.types.product_search_service import RemoveProductFromProductSetRequest -from google.cloud.vision_v1.types.product_search_service import UpdateProductRequest -from google.cloud.vision_v1.types.product_search_service import UpdateProductSetRequest -from google.cloud.vision_v1.types.text_annotation import Block -from google.cloud.vision_v1.types.text_annotation import Page -from google.cloud.vision_v1.types.text_annotation import Paragraph -from google.cloud.vision_v1.types.text_annotation import Symbol -from google.cloud.vision_v1.types.text_annotation import TextAnnotation -from google.cloud.vision_v1.types.text_annotation import Word -from google.cloud.vision_v1.types.web_detection import WebDetection - -__all__ = ('ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', - 'ProductSearchClient', - 'ProductSearchAsyncClient', - 'BoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileRequest', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'AsyncBatchAnnotateImagesRequest', - 'AsyncBatchAnnotateImagesResponse', - 'BatchAnnotateFilesRequest', - 'BatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocalizedObjectAnnotation', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'ProductSearchParams', - 'ProductSearchResults', - 'AddProductToProductSetRequest', - 'BatchOperationMetadata', - 'CreateProductRequest', - 'CreateProductSetRequest', - 'CreateReferenceImageRequest', - 'DeleteProductRequest', - 'DeleteProductSetRequest', - 'DeleteReferenceImageRequest', - 'GetProductRequest', - 'GetProductSetRequest', - 'GetReferenceImageRequest', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ListProductsRequest', - 'ListProductsResponse', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'Product', - 'ProductSet', - 'ProductSetPurgeConfig', - 'PurgeProductsRequest', - 'ReferenceImage', - 'RemoveProductFromProductSetRequest', - 'UpdateProductRequest', - 'UpdateProductSetRequest', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1/google/cloud/vision/py.typed b/owl-bot-staging/v1/google/cloud/vision/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1/google/cloud/vision/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/__init__.py deleted file mode 100644 index 21daa9df..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/__init__.py +++ /dev/null @@ -1,196 +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.image_annotator import ImageAnnotatorClient -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.product_search import ProductSearchClient -from .services.product_search import ProductSearchAsyncClient - -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Position -from .types.geometry import Vertex -from .types.image_annotator import AnnotateFileRequest -from .types.image_annotator import AnnotateFileResponse -from .types.image_annotator import AnnotateImageRequest -from .types.image_annotator import AnnotateImageResponse -from .types.image_annotator import AsyncAnnotateFileRequest -from .types.image_annotator import AsyncAnnotateFileResponse -from .types.image_annotator import AsyncBatchAnnotateFilesRequest -from .types.image_annotator import AsyncBatchAnnotateFilesResponse -from .types.image_annotator import AsyncBatchAnnotateImagesRequest -from .types.image_annotator import AsyncBatchAnnotateImagesResponse -from .types.image_annotator import BatchAnnotateFilesRequest -from .types.image_annotator import BatchAnnotateFilesResponse -from .types.image_annotator import BatchAnnotateImagesRequest -from .types.image_annotator import BatchAnnotateImagesResponse -from .types.image_annotator import ColorInfo -from .types.image_annotator import CropHint -from .types.image_annotator import CropHintsAnnotation -from .types.image_annotator import CropHintsParams -from .types.image_annotator import DominantColorsAnnotation -from .types.image_annotator import EntityAnnotation -from .types.image_annotator import FaceAnnotation -from .types.image_annotator import Feature -from .types.image_annotator import GcsDestination -from .types.image_annotator import GcsSource -from .types.image_annotator import Image -from .types.image_annotator import ImageAnnotationContext -from .types.image_annotator import ImageContext -from .types.image_annotator import ImageProperties -from .types.image_annotator import ImageSource -from .types.image_annotator import InputConfig -from .types.image_annotator import LatLongRect -from .types.image_annotator import LocalizedObjectAnnotation -from .types.image_annotator import LocationInfo -from .types.image_annotator import OperationMetadata -from .types.image_annotator import OutputConfig -from .types.image_annotator import Property -from .types.image_annotator import SafeSearchAnnotation -from .types.image_annotator import TextDetectionParams -from .types.image_annotator import WebDetectionParams -from .types.image_annotator import Likelihood -from .types.product_search import ProductSearchParams -from .types.product_search import ProductSearchResults -from .types.product_search_service import AddProductToProductSetRequest -from .types.product_search_service import BatchOperationMetadata -from .types.product_search_service import CreateProductRequest -from .types.product_search_service import CreateProductSetRequest -from .types.product_search_service import CreateReferenceImageRequest -from .types.product_search_service import DeleteProductRequest -from .types.product_search_service import DeleteProductSetRequest -from .types.product_search_service import DeleteReferenceImageRequest -from .types.product_search_service import GetProductRequest -from .types.product_search_service import GetProductSetRequest -from .types.product_search_service import GetReferenceImageRequest -from .types.product_search_service import ImportProductSetsGcsSource -from .types.product_search_service import ImportProductSetsInputConfig -from .types.product_search_service import ImportProductSetsRequest -from .types.product_search_service import ImportProductSetsResponse -from .types.product_search_service import ListProductSetsRequest -from .types.product_search_service import ListProductSetsResponse -from .types.product_search_service import ListProductsInProductSetRequest -from .types.product_search_service import ListProductsInProductSetResponse -from .types.product_search_service import ListProductsRequest -from .types.product_search_service import ListProductsResponse -from .types.product_search_service import ListReferenceImagesRequest -from .types.product_search_service import ListReferenceImagesResponse -from .types.product_search_service import Product -from .types.product_search_service import ProductSet -from .types.product_search_service import ProductSetPurgeConfig -from .types.product_search_service import PurgeProductsRequest -from .types.product_search_service import ReferenceImage -from .types.product_search_service import RemoveProductFromProductSetRequest -from .types.product_search_service import UpdateProductRequest -from .types.product_search_service import UpdateProductSetRequest -from .types.text_annotation import Block -from .types.text_annotation import Page -from .types.text_annotation import Paragraph -from .types.text_annotation import Symbol -from .types.text_annotation import TextAnnotation -from .types.text_annotation import Word -from .types.web_detection import WebDetection - -__all__ = ( - 'ImageAnnotatorAsyncClient', - 'ProductSearchAsyncClient', -'AddProductToProductSetRequest', -'AnnotateFileRequest', -'AnnotateFileResponse', -'AnnotateImageRequest', -'AnnotateImageResponse', -'AsyncAnnotateFileRequest', -'AsyncAnnotateFileResponse', -'AsyncBatchAnnotateFilesRequest', -'AsyncBatchAnnotateFilesResponse', -'AsyncBatchAnnotateImagesRequest', -'AsyncBatchAnnotateImagesResponse', -'BatchAnnotateFilesRequest', -'BatchAnnotateFilesResponse', -'BatchAnnotateImagesRequest', -'BatchAnnotateImagesResponse', -'BatchOperationMetadata', -'Block', -'BoundingPoly', -'ColorInfo', -'CreateProductRequest', -'CreateProductSetRequest', -'CreateReferenceImageRequest', -'CropHint', -'CropHintsAnnotation', -'CropHintsParams', -'DeleteProductRequest', -'DeleteProductSetRequest', -'DeleteReferenceImageRequest', -'DominantColorsAnnotation', -'EntityAnnotation', -'FaceAnnotation', -'Feature', -'GcsDestination', -'GcsSource', -'GetProductRequest', -'GetProductSetRequest', -'GetReferenceImageRequest', -'Image', -'ImageAnnotationContext', -'ImageAnnotatorClient', -'ImageContext', -'ImageProperties', -'ImageSource', -'ImportProductSetsGcsSource', -'ImportProductSetsInputConfig', -'ImportProductSetsRequest', -'ImportProductSetsResponse', -'InputConfig', -'LatLongRect', -'Likelihood', -'ListProductSetsRequest', -'ListProductSetsResponse', -'ListProductsInProductSetRequest', -'ListProductsInProductSetResponse', -'ListProductsRequest', -'ListProductsResponse', -'ListReferenceImagesRequest', -'ListReferenceImagesResponse', -'LocalizedObjectAnnotation', -'LocationInfo', -'NormalizedVertex', -'OperationMetadata', -'OutputConfig', -'Page', -'Paragraph', -'Position', -'Product', -'ProductSearchClient', -'ProductSearchParams', -'ProductSearchResults', -'ProductSet', -'ProductSetPurgeConfig', -'Property', -'PurgeProductsRequest', -'ReferenceImage', -'RemoveProductFromProductSetRequest', -'SafeSearchAnnotation', -'Symbol', -'TextAnnotation', -'TextDetectionParams', -'UpdateProductRequest', -'UpdateProductSetRequest', -'Vertex', -'WebDetection', -'WebDetectionParams', -'Word', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json b/owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json deleted file mode 100644 index 71b189b5..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/gapic_metadata.json +++ /dev/null @@ -1,267 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.vision_v1", - "protoPackage": "google.cloud.vision.v1", - "schema": "1.0", - "services": { - "ImageAnnotator": { - "clients": { - "grpc": { - "libraryClient": "ImageAnnotatorClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "AsyncBatchAnnotateImages": { - "methods": [ - "async_batch_annotate_images" - ] - }, - "BatchAnnotateFiles": { - "methods": [ - "batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ImageAnnotatorAsyncClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "AsyncBatchAnnotateImages": { - "methods": [ - "async_batch_annotate_images" - ] - }, - "BatchAnnotateFiles": { - "methods": [ - "batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - } - } - }, - "ProductSearch": { - "clients": { - "grpc": { - "libraryClient": "ProductSearchClient", - "rpcs": { - "AddProductToProductSet": { - "methods": [ - "add_product_to_product_set" - ] - }, - "CreateProduct": { - "methods": [ - "create_product" - ] - }, - "CreateProductSet": { - "methods": [ - "create_product_set" - ] - }, - "CreateReferenceImage": { - "methods": [ - "create_reference_image" - ] - }, - "DeleteProduct": { - "methods": [ - "delete_product" - ] - }, - "DeleteProductSet": { - "methods": [ - "delete_product_set" - ] - }, - "DeleteReferenceImage": { - "methods": [ - "delete_reference_image" - ] - }, - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "GetProductSet": { - "methods": [ - "get_product_set" - ] - }, - "GetReferenceImage": { - "methods": [ - "get_reference_image" - ] - }, - "ImportProductSets": { - "methods": [ - "import_product_sets" - ] - }, - "ListProductSets": { - "methods": [ - "list_product_sets" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - }, - "ListProductsInProductSet": { - "methods": [ - "list_products_in_product_set" - ] - }, - "ListReferenceImages": { - "methods": [ - "list_reference_images" - ] - }, - "PurgeProducts": { - "methods": [ - "purge_products" - ] - }, - "RemoveProductFromProductSet": { - "methods": [ - "remove_product_from_product_set" - ] - }, - "UpdateProduct": { - "methods": [ - "update_product" - ] - }, - "UpdateProductSet": { - "methods": [ - "update_product_set" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ProductSearchAsyncClient", - "rpcs": { - "AddProductToProductSet": { - "methods": [ - "add_product_to_product_set" - ] - }, - "CreateProduct": { - "methods": [ - "create_product" - ] - }, - "CreateProductSet": { - "methods": [ - "create_product_set" - ] - }, - "CreateReferenceImage": { - "methods": [ - "create_reference_image" - ] - }, - "DeleteProduct": { - "methods": [ - "delete_product" - ] - }, - "DeleteProductSet": { - "methods": [ - "delete_product_set" - ] - }, - "DeleteReferenceImage": { - "methods": [ - "delete_reference_image" - ] - }, - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "GetProductSet": { - "methods": [ - "get_product_set" - ] - }, - "GetReferenceImage": { - "methods": [ - "get_reference_image" - ] - }, - "ImportProductSets": { - "methods": [ - "import_product_sets" - ] - }, - "ListProductSets": { - "methods": [ - "list_product_sets" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - }, - "ListProductsInProductSet": { - "methods": [ - "list_products_in_product_set" - ] - }, - "ListReferenceImages": { - "methods": [ - "list_reference_images" - ] - }, - "PurgeProducts": { - "methods": [ - "purge_products" - ] - }, - "RemoveProductFromProductSet": { - "methods": [ - "remove_product_from_product_set" - ] - }, - "UpdateProduct": { - "methods": [ - "update_product" - ] - }, - "UpdateProductSet": { - "methods": [ - "update_product_set" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/py.typed b/owl-bot-staging/v1/google/cloud/vision_v1/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_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/vision_v1/services/image_annotator/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/__init__.py deleted file mode 100644 index 3cbfa2fa..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/__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 ImageAnnotatorClient -from .async_client import ImageAnnotatorAsyncClient - -__all__ = ( - 'ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py deleted file mode 100644 index 21891218..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/async_client.py +++ /dev/null @@ -1,525 +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.vision_v1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport -from .client import ImageAnnotatorClient - - -class ImageAnnotatorAsyncClient: - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - _client: ImageAnnotatorClient - - DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT - - product_path = staticmethod(ImageAnnotatorClient.product_path) - parse_product_path = staticmethod(ImageAnnotatorClient.parse_product_path) - product_set_path = staticmethod(ImageAnnotatorClient.product_set_path) - parse_product_set_path = staticmethod(ImageAnnotatorClient.parse_product_set_path) - common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) - parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) - common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) - parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) - common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) - parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) - common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) - parse_common_location_path = staticmethod(ImageAnnotatorClient.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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def batch_annotate_images(self, - request: image_annotator.BatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (:class:`google.cloud.vision_v1.types.BatchAnnotateImagesRequest`): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def batch_annotate_files(self, - request: image_annotator.BatchAnnotateFilesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateFilesResponse: - r"""Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Args: - request (:class:`google.cloud.vision_v1.types.BatchAnnotateFilesRequest`): - The request object. A list of requests to annotate files - using the BatchAnnotateFiles API. - requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]`): - Required. The list of file annotation - requests. Right now we support only one - AnnotateFileRequest in - BatchAnnotateFilesRequest. - - 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.cloud.vision_v1.types.BatchAnnotateFilesResponse: - A list of file annotation responses. - """ - # 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 = image_annotator.BatchAnnotateFilesRequest(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_annotate_files, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def async_batch_annotate_images(self, - request: image_annotator.AsyncBatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - output_config: image_annotator.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Args: - request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest`): - The request object. Request for async image annotation - for a list of images. - requests (:class:`Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]`): - Required. Individual image annotation - requests for this batch. - - This corresponds to the ``requests`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - output_config (:class:`google.cloud.vision_v1.types.OutputConfig`): - Required. The desired output location - and metadata (e.g. format). - - This corresponds to the ``output_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.vision_v1.types.AsyncBatchAnnotateImagesResponse` - Response to an async batch image annotation request. - - """ - # 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, output_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 = image_annotator.AsyncBatchAnnotateImagesRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if output_config is not None: - request.output_config = output_config - 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.async_batch_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # 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, - image_annotator.AsyncBatchAnnotateImagesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - async def async_batch_annotate_files(self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (:class:`google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest`): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]`): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorAsyncClient", -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py deleted file mode 100644 index 17aa88a0..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/client.py +++ /dev/null @@ -1,703 +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 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.vision_v1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ImageAnnotatorGrpcTransport -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -class ImageAnnotatorClientMeta(type): - """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] - _transport_registry["grpc"] = ImageAnnotatorGrpcTransport - _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ImageAnnotatorTransport]: - """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - @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 = "vision.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: - ImageAnnotatorClient: 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: - ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(project: str,location: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_set_path(project: str,location: str,product_set: str,) -> str: - """Returns a fully-qualified product_set string.""" - return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - - @staticmethod - def parse_product_set_path(path: str) -> Dict[str,str]: - """Parses a product_set path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?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, ImageAnnotatorTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): - # transport is a ImageAnnotatorTransport 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, - always_use_jwt_access=True, - ) - - def batch_annotate_images(self, - request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (Union[google.cloud.vision_v1.types.BatchAnnotateImagesRequest, dict]): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 image_annotator.BatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): - request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def batch_annotate_files(self, - request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateFilesResponse: - r"""Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Args: - request (Union[google.cloud.vision_v1.types.BatchAnnotateFilesRequest, dict]): - The request object. A list of requests to annotate files - using the BatchAnnotateFiles API. - requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]): - Required. The list of file annotation - requests. Right now we support only one - AnnotateFileRequest in - BatchAnnotateFilesRequest. - - 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.cloud.vision_v1.types.BatchAnnotateFilesResponse: - A list of file annotation responses. - """ - # 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 image_annotator.BatchAnnotateFilesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateFilesRequest): - request = image_annotator.BatchAnnotateFilesRequest(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_annotate_files] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def async_batch_annotate_images(self, - request: Union[image_annotator.AsyncBatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - output_config: image_annotator.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Args: - request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateImagesRequest, dict]): - The request object. Request for async image annotation - for a list of images. - requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - - This corresponds to the ``requests`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - output_config (google.cloud.vision_v1.types.OutputConfig): - Required. The desired output location - and metadata (e.g. format). - - This corresponds to the ``output_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.vision_v1.types.AsyncBatchAnnotateImagesResponse` - Response to an async batch image annotation request. - - """ - # 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, output_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 image_annotator.AsyncBatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.AsyncBatchAnnotateImagesRequest): - request = image_annotator.AsyncBatchAnnotateImagesRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if requests is not None: - request.requests = requests - if output_config is not None: - request.output_config = output_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.async_batch_annotate_images] - - # 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, - image_annotator.AsyncBatchAnnotateImagesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - def async_batch_annotate_files(self, - request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (Union[google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest, dict]): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 image_annotator.AsyncBatchAnnotateFilesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): - request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorClient", -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/__init__.py deleted file mode 100644 index 94f01250..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/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 ImageAnnotatorTransport -from .grpc import ImageAnnotatorGrpcTransport -from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] -_transport_registry['grpc'] = ImageAnnotatorGrpcTransport -_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport - -__all__ = ( - 'ImageAnnotatorTransport', - 'ImageAnnotatorGrpcTransport', - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py deleted file mode 100644 index 1f72a9a6..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/base.py +++ /dev/null @@ -1,255 +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.vision_v1.types import image_annotator -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-vision', - ).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 ImageAnnotatorTransport(abc.ABC): - """Abstract transport class for ImageAnnotator.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( - self.batch_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.batch_annotate_files: gapic_v1.method.wrap_method( - self.batch_annotate_files, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.async_batch_annotate_images: gapic_v1.method.wrap_method( - self.async_batch_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.async_batch_annotate_files: gapic_v1.method.wrap_method( - self.async_batch_annotate_files, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Union[ - image_annotator.BatchAnnotateImagesResponse, - Awaitable[image_annotator.BatchAnnotateImagesResponse] - ]]: - raise NotImplementedError() - - @property - def batch_annotate_files(self) -> Callable[ - [image_annotator.BatchAnnotateFilesRequest], - Union[ - image_annotator.BatchAnnotateFilesResponse, - Awaitable[image_annotator.BatchAnnotateFilesResponse] - ]]: - raise NotImplementedError() - - @property - def async_batch_annotate_images(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateImagesRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ImageAnnotatorTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py deleted file mode 100644 index 7dce19bd..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc.py +++ /dev/null @@ -1,379 +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.vision_v1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO - - -class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): - """gRPC backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - image_annotator.BatchAnnotateImagesResponse]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - ~.BatchAnnotateImagesResponse]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def batch_annotate_files(self) -> Callable[ - [image_annotator.BatchAnnotateFilesRequest], - image_annotator.BatchAnnotateFilesResponse]: - r"""Return a callable for the batch annotate files method over gRPC. - - Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Returns: - Callable[[~.BatchAnnotateFilesRequest], - ~.BatchAnnotateFilesResponse]: - 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_annotate_files' not in self._stubs: - self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateFiles', - request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, - ) - return self._stubs['batch_annotate_files'] - - @property - def async_batch_annotate_images(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateImagesRequest], - operations_pb2.Operation]: - r"""Return a callable for the async batch annotate images method over gRPC. - - Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Returns: - Callable[[~.AsyncBatchAnnotateImagesRequest], - ~.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 'async_batch_annotate_images' not in self._stubs: - self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages', - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - operations_pb2.Operation]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - ~.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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ImageAnnotatorGrpcTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py deleted file mode 100644 index 809204b5..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py +++ /dev/null @@ -1,384 +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.vision_v1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .grpc import ImageAnnotatorGrpcTransport - - -class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): - """gRPC AsyncIO backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Awaitable[image_annotator.BatchAnnotateImagesResponse]]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - Awaitable[~.BatchAnnotateImagesResponse]]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def batch_annotate_files(self) -> Callable[ - [image_annotator.BatchAnnotateFilesRequest], - Awaitable[image_annotator.BatchAnnotateFilesResponse]]: - r"""Return a callable for the batch annotate files method over gRPC. - - Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Returns: - Callable[[~.BatchAnnotateFilesRequest], - Awaitable[~.BatchAnnotateFilesResponse]]: - 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_annotate_files' not in self._stubs: - self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/BatchAnnotateFiles', - request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, - ) - return self._stubs['batch_annotate_files'] - - @property - def async_batch_annotate_images(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateImagesRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the async batch annotate images method over gRPC. - - Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Returns: - Callable[[~.AsyncBatchAnnotateImagesRequest], - 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 'async_batch_annotate_images' not in self._stubs: - self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages', - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - 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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__init__.py deleted file mode 100644 index cf79a54d..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/__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 ProductSearchClient -from .async_client import ProductSearchAsyncClient - -__all__ = ( - 'ProductSearchClient', - 'ProductSearchAsyncClient', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py deleted file mode 100644 index c97fe0c5..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/async_client.py +++ /dev/null @@ -1,2104 +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.vision_v1.services.product_search import pagers -from google.cloud.vision_v1.types import geometry -from google.cloud.vision_v1.types import product_search_service -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport -from .client import ProductSearchClient - - -class ProductSearchAsyncClient: - """Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1.Product] has a collection - of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - """ - - _client: ProductSearchClient - - DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT - - product_path = staticmethod(ProductSearchClient.product_path) - parse_product_path = staticmethod(ProductSearchClient.parse_product_path) - product_set_path = staticmethod(ProductSearchClient.product_set_path) - parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) - reference_image_path = staticmethod(ProductSearchClient.reference_image_path) - parse_reference_image_path = staticmethod(ProductSearchClient.parse_reference_image_path) - common_billing_account_path = staticmethod(ProductSearchClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductSearchClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ProductSearchClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductSearchClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductSearchClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductSearchClient.parse_common_organization_path) - common_project_path = staticmethod(ProductSearchClient.common_project_path) - parse_common_project_path = staticmethod(ProductSearchClient.parse_common_project_path) - common_location_path = staticmethod(ProductSearchClient.common_location_path) - parse_common_location_path = staticmethod(ProductSearchClient.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: - ProductSearchAsyncClient: The constructed client. - """ - return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, 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: - ProductSearchAsyncClient: The constructed client. - """ - return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ProductSearchTransport: - """Returns the transport used by the client instance. - - Returns: - ProductSearchTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ProductSearchClient).get_transport_class, type(ProductSearchClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ProductSearchTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product search 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, ~.ProductSearchTransport]): 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 = ProductSearchClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def create_product_set(self, - request: product_search_service.CreateProductSetRequest = None, - *, - parent: str = None, - product_set: product_search_service.ProductSet = None, - product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Args: - request (:class:`google.cloud.vision_v1.types.CreateProductSetRequest`): - The request object. Request message for the - `CreateProductSet` method. - parent (:class:`str`): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set (:class:`google.cloud.vision_v1.types.ProductSet`): - Required. The ProductSet to create. - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set_id (:class:`str`): - A user-supplied resource id for this ProductSet. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_set_id`` 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.vision_v1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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, product_set, product_set_id]) - 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 = product_search_service.CreateProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product_set is not None: - request.product_set = product_set - if product_set_id is not None: - request.product_set_id = product_set_id - - # 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_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def list_product_sets(self, - request: product_search_service.ListProductSetsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductSetsAsyncPager: - r"""Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1.types.ListProductSetsRequest`): - The request object. Request message for the - `ListProductSets` method. - parent (:class:`str`): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.vision_v1.services.product_search.pagers.ListProductSetsAsyncPager: - Response message for the ListProductSets method. - - 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 = product_search_service.ListProductSetsRequest(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_product_sets, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductSetsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_product_set(self, - request: product_search_service.GetProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (:class:`google.cloud.vision_v1.types.GetProductSetRequest`): - The request object. Request message for the - `GetProductSet` method. - name (:class:`str`): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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 = product_search_service.GetProductSetRequest(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.get_product_set, - 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=600.0, - ), - default_timeout=600.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 update_product_set(self, - request: product_search_service.UpdateProductSetRequest = None, - *, - product_set: product_search_service.ProductSet = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Args: - request (:class:`google.cloud.vision_v1.types.UpdateProductSetRequest`): - The request object. Request message for the - `UpdateProductSet` method. - product_set (:class:`google.cloud.vision_v1.types.ProductSet`): - Required. The ProductSet resource - which replaces the one on the server. - - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask path is ``display_name``. - - This corresponds to the ``update_mask`` 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.vision_v1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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([product_set, update_mask]) - 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 = product_search_service.UpdateProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_set is not None: - request.product_set = product_set - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_product_set, - 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=600.0, - ), - default_timeout=600.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(( - ("product_set.name", request.product_set.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product_set(self, - request: product_search_service.DeleteProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (:class:`google.cloud.vision_v1.types.DeleteProductSetRequest`): - The request object. Request message for the - `DeleteProductSet` method. - name (:class:`str`): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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. - """ - # 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 = product_search_service.DeleteProductSetRequest(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_product_set, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def create_product(self, - request: product_search_service.CreateProductRequest = None, - *, - parent: str = None, - product: product_search_service.Product = None, - product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Args: - request (:class:`google.cloud.vision_v1.types.CreateProductRequest`): - The request object. Request message for the - `CreateProduct` method. - parent (:class:`str`): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`google.cloud.vision_v1.types.Product`): - Required. The product to create. - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_id (:class:`str`): - A user-supplied resource id for this Product. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_id`` 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.vision_v1.types.Product: - A Product contains ReferenceImages. - """ - # 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, product, product_id]) - 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 = product_search_service.CreateProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product is not None: - request.product = product - if product_id is not None: - request.product_id = product_id - - # 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_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def list_products(self, - request: product_search_service.ListProductsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsAsyncPager: - r"""Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1.types.ListProductsRequest`): - The request object. Request message for the - `ListProducts` method. - parent (:class:`str`): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - - 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.vision_v1.services.product_search.pagers.ListProductsAsyncPager: - Response message for the ListProducts method. - - 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 = product_search_service.ListProductsRequest(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_products, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_product(self, - request: product_search_service.GetProductRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Args: - request (:class:`google.cloud.vision_v1.types.GetProductRequest`): - The request object. Request message for the `GetProduct` - method. - name (:class:`str`): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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.vision_v1.types.Product: - A Product contains ReferenceImages. - """ - # 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 = product_search_service.GetProductRequest(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.get_product, - 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=600.0, - ), - default_timeout=600.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 update_product(self, - request: product_search_service.UpdateProductRequest = None, - *, - product: product_search_service.Product = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Args: - request (:class:`google.cloud.vision_v1.types.UpdateProductRequest`): - The request object. Request message for the - `UpdateProduct` method. - product (:class:`google.cloud.vision_v1.types.Product`): - Required. The Product resource which - replaces the one on the server. - product.name is immutable. - - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask paths include ``product_labels``, ``display_name``, - and ``description``. - - This corresponds to the ``update_mask`` 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.vision_v1.types.Product: - A Product contains ReferenceImages. - """ - # 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([product, update_mask]) - 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 = product_search_service.UpdateProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product is not None: - request.product = product - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_product, - 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=600.0, - ), - default_timeout=600.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(( - ("product.name", request.product.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product(self, - request: product_search_service.DeleteProductRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Args: - request (:class:`google.cloud.vision_v1.types.DeleteProductRequest`): - The request object. Request message for the - `DeleteProduct` method. - name (:class:`str`): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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. - """ - # 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 = product_search_service.DeleteProductRequest(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_product, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def create_reference_image(self, - request: product_search_service.CreateReferenceImageRequest = None, - *, - parent: str = None, - reference_image: product_search_service.ReferenceImage = None, - reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Args: - request (:class:`google.cloud.vision_v1.types.CreateReferenceImageRequest`): - The request object. Request message for the - `CreateReferenceImage` method. - parent (:class:`str`): - Required. Resource name of the product in which to - create the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image (:class:`google.cloud.vision_v1.types.ReferenceImage`): - Required. The reference image to - create. If an image ID is specified, it - is ignored. - - This corresponds to the ``reference_image`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image_id (:class:`str`): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value - as the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``reference_image_id`` 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.vision_v1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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, reference_image, reference_image_id]) - 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 = product_search_service.CreateReferenceImageRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if reference_image is not None: - request.reference_image = reference_image - if reference_image_id is not None: - request.reference_image_id = reference_image_id - - # 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_reference_image, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def delete_reference_image(self, - request: product_search_service.DeleteReferenceImageRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (:class:`google.cloud.vision_v1.types.DeleteReferenceImageRequest`): - The request object. Request message for the - `DeleteReferenceImage` method. - name (:class:`str`): - Required. The resource name of the reference image to - delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - - 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. - """ - # 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 = product_search_service.DeleteReferenceImageRequest(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_reference_image, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_reference_images(self, - request: product_search_service.ListReferenceImagesRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListReferenceImagesAsyncPager: - r"""Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Args: - request (:class:`google.cloud.vision_v1.types.ListReferenceImagesRequest`): - The request object. Request message for the - `ListReferenceImages` method. - parent (:class:`str`): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - 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.vision_v1.services.product_search.pagers.ListReferenceImagesAsyncPager: - Response message for the ListReferenceImages method. - - 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 = product_search_service.ListReferenceImagesRequest(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_reference_images, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListReferenceImagesAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_reference_image(self, - request: product_search_service.GetReferenceImageRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Args: - request (:class:`google.cloud.vision_v1.types.GetReferenceImageRequest`): - The request object. Request message for the - `GetReferenceImage` method. - name (:class:`str`): - Required. The resource name of the ReferenceImage to - get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - 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.vision_v1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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 = product_search_service.GetReferenceImageRequest(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.get_reference_image, - 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=600.0, - ), - default_timeout=600.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 add_product_to_product_set(self, - request: product_search_service.AddProductToProductSetRequest = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Args: - request (:class:`google.cloud.vision_v1.types.AddProductToProductSetRequest`): - The request object. Request message for the - `AddProductToProductSet` method. - name (:class:`str`): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`str`): - Required. The resource name for the Product to be added - to this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 = product_search_service.AddProductToProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.add_product_to_product_set, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def remove_product_from_product_set(self, - request: product_search_service.RemoveProductFromProductSetRequest = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Removes a Product from the specified ProductSet. - - Args: - request (:class:`google.cloud.vision_v1.types.RemoveProductFromProductSetRequest`): - The request object. Request message for the - `RemoveProductFromProductSet` method. - name (:class:`str`): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`str`): - Required. The resource name for the Product to be - removed from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 = product_search_service.RemoveProductFromProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.remove_product_from_product_set, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_products_in_product_set(self, - request: product_search_service.ListProductsInProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsInProductSetAsyncPager: - r"""Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1.types.ListProductsInProductSetRequest`): - The request object. Request message for the - `ListProductsInProductSet` method. - name (:class:`str`): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1.services.product_search.pagers.ListProductsInProductSetAsyncPager: - Response message for the ListProductsInProductSet - method. - - 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([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 = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsInProductSetAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def import_product_sets(self, - request: product_search_service.ImportProductSetsRequest = None, - *, - parent: str = None, - input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. - - Args: - request (:class:`google.cloud.vision_v1.types.ImportProductSetsRequest`): - The request object. Request message for the - `ImportProductSets` method. - parent (:class:`str`): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - input_config (:class:`google.cloud.vision_v1.types.ImportProductSetsInputConfig`): - Required. The input content for the - list of requests. - - This corresponds to the ``input_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.vision_v1.types.ImportProductSetsResponse` - Response message for the ImportProductSets method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - """ - # 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, input_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 = product_search_service.ImportProductSetsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if input_config is not None: - request.input_config = input_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.import_product_sets, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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, - product_search_service.ImportProductSetsResponse, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - async def purge_products(self, - request: product_search_service.PurgeProductsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Args: - request (:class:`google.cloud.vision_v1.types.PurgeProductsRequest`): - The request object. Request message for the - `PurgeProducts` method. - parent (:class:`str`): - Required. The project and location in which the Products - should be deleted. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.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([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 = product_search_service.PurgeProductsRequest(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.purge_products, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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, - empty_pb2.Empty, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ProductSearchAsyncClient", -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py deleted file mode 100644 index 4979db09..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/client.py +++ /dev/null @@ -1,2196 +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 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.vision_v1.services.product_search import pagers -from google.cloud.vision_v1.types import geometry -from google.cloud.vision_v1.types import product_search_service -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ProductSearchGrpcTransport -from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport - - -class ProductSearchClientMeta(type): - """Metaclass for the ProductSearch 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[ProductSearchTransport]] - _transport_registry["grpc"] = ProductSearchGrpcTransport - _transport_registry["grpc_asyncio"] = ProductSearchGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ProductSearchTransport]: - """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 ProductSearchClient(metaclass=ProductSearchClientMeta): - """Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1.Product] has a collection - of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - """ - - @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 = "vision.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: - ProductSearchClient: 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: - ProductSearchClient: 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) -> ProductSearchTransport: - """Returns the transport used by the client instance. - - Returns: - ProductSearchTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(project: str,location: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_set_path(project: str,location: str,product_set: str,) -> str: - """Returns a fully-qualified product_set string.""" - return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - - @staticmethod - def parse_product_set_path(path: str) -> Dict[str,str]: - """Parses a product_set path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def reference_image_path(project: str,location: str,product: str,reference_image: str,) -> str: - """Returns a fully-qualified reference_image string.""" - return "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) - - @staticmethod - def parse_reference_image_path(path: str) -> Dict[str,str]: - """Parses a reference_image path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)/referenceImages/(?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, ProductSearchTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product search 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, ProductSearchTransport]): 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, ProductSearchTransport): - # transport is a ProductSearchTransport 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, - always_use_jwt_access=True, - ) - - def create_product_set(self, - request: Union[product_search_service.CreateProductSetRequest, dict] = None, - *, - parent: str = None, - product_set: product_search_service.ProductSet = None, - product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Args: - request (Union[google.cloud.vision_v1.types.CreateProductSetRequest, dict]): - The request object. Request message for the - `CreateProductSet` method. - parent (str): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set (google.cloud.vision_v1.types.ProductSet): - Required. The ProductSet to create. - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set_id (str): - A user-supplied resource id for this ProductSet. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_set_id`` 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.vision_v1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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, product_set, product_set_id]) - 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 product_search_service.CreateProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateProductSetRequest): - request = product_search_service.CreateProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product_set is not None: - request.product_set = product_set - if product_set_id is not None: - request.product_set_id = product_set_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_product_set] - - # 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_product_sets(self, - request: Union[product_search_service.ListProductSetsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductSetsPager: - r"""Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Args: - request (Union[google.cloud.vision_v1.types.ListProductSetsRequest, dict]): - The request object. Request message for the - `ListProductSets` method. - parent (str): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.vision_v1.services.product_search.pagers.ListProductSetsPager: - Response message for the ListProductSets method. - - 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 product_search_service.ListProductSetsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductSetsRequest): - request = product_search_service.ListProductSetsRequest(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_product_sets] - - # 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.ListProductSetsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_product_set(self, - request: Union[product_search_service.GetProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (Union[google.cloud.vision_v1.types.GetProductSetRequest, dict]): - The request object. Request message for the - `GetProductSet` method. - name (str): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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 product_search_service.GetProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetProductSetRequest): - request = product_search_service.GetProductSetRequest(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.get_product_set] - - # 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 update_product_set(self, - request: Union[product_search_service.UpdateProductSetRequest, dict] = None, - *, - product_set: product_search_service.ProductSet = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Args: - request (Union[google.cloud.vision_v1.types.UpdateProductSetRequest, dict]): - The request object. Request message for the - `UpdateProductSet` method. - product_set (google.cloud.vision_v1.types.ProductSet): - Required. The ProductSet resource - which replaces the one on the server. - - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask path is ``display_name``. - - This corresponds to the ``update_mask`` 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.vision_v1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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([product_set, update_mask]) - 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 product_search_service.UpdateProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.UpdateProductSetRequest): - request = product_search_service.UpdateProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_set is not None: - request.product_set = product_set - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product_set] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_set.name", request.product_set.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product_set(self, - request: Union[product_search_service.DeleteProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (Union[google.cloud.vision_v1.types.DeleteProductSetRequest, dict]): - The request object. Request message for the - `DeleteProductSet` method. - name (str): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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. - """ - # 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 product_search_service.DeleteProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteProductSetRequest): - request = product_search_service.DeleteProductSetRequest(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_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def create_product(self, - request: Union[product_search_service.CreateProductRequest, dict] = None, - *, - parent: str = None, - product: product_search_service.Product = None, - product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Args: - request (Union[google.cloud.vision_v1.types.CreateProductRequest, dict]): - The request object. Request message for the - `CreateProduct` method. - parent (str): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (google.cloud.vision_v1.types.Product): - Required. The product to create. - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_id (str): - A user-supplied resource id for this Product. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_id`` 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.vision_v1.types.Product: - A Product contains ReferenceImages. - """ - # 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, product, product_id]) - 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 product_search_service.CreateProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateProductRequest): - request = product_search_service.CreateProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product is not None: - request.product = product - if product_id is not None: - request.product_id = product_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_product] - - # 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_products(self, - request: Union[product_search_service.ListProductsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsPager: - r"""Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (Union[google.cloud.vision_v1.types.ListProductsRequest, dict]): - The request object. Request message for the - `ListProducts` method. - parent (str): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - - 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.vision_v1.services.product_search.pagers.ListProductsPager: - Response message for the ListProducts method. - - 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 product_search_service.ListProductsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductsRequest): - request = product_search_service.ListProductsRequest(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_products] - - # 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.ListProductsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_product(self, - request: Union[product_search_service.GetProductRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Args: - request (Union[google.cloud.vision_v1.types.GetProductRequest, dict]): - The request object. Request message for the `GetProduct` - method. - name (str): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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.vision_v1.types.Product: - A Product contains ReferenceImages. - """ - # 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 product_search_service.GetProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetProductRequest): - request = product_search_service.GetProductRequest(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.get_product] - - # 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 update_product(self, - request: Union[product_search_service.UpdateProductRequest, dict] = None, - *, - product: product_search_service.Product = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Args: - request (Union[google.cloud.vision_v1.types.UpdateProductRequest, dict]): - The request object. Request message for the - `UpdateProduct` method. - product (google.cloud.vision_v1.types.Product): - Required. The Product resource which - replaces the one on the server. - product.name is immutable. - - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask paths include ``product_labels``, ``display_name``, - and ``description``. - - This corresponds to the ``update_mask`` 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.vision_v1.types.Product: - A Product contains ReferenceImages. - """ - # 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([product, update_mask]) - 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 product_search_service.UpdateProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.UpdateProductRequest): - request = product_search_service.UpdateProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product is not None: - request.product = product - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product.name", request.product.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product(self, - request: Union[product_search_service.DeleteProductRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Args: - request (Union[google.cloud.vision_v1.types.DeleteProductRequest, dict]): - The request object. Request message for the - `DeleteProduct` method. - name (str): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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. - """ - # 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 product_search_service.DeleteProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteProductRequest): - request = product_search_service.DeleteProductRequest(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_product] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def create_reference_image(self, - request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, - *, - parent: str = None, - reference_image: product_search_service.ReferenceImage = None, - reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Args: - request (Union[google.cloud.vision_v1.types.CreateReferenceImageRequest, dict]): - The request object. Request message for the - `CreateReferenceImage` method. - parent (str): - Required. Resource name of the product in which to - create the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image (google.cloud.vision_v1.types.ReferenceImage): - Required. The reference image to - create. If an image ID is specified, it - is ignored. - - This corresponds to the ``reference_image`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image_id (str): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value - as the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``reference_image_id`` 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.vision_v1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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, reference_image, reference_image_id]) - 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 product_search_service.CreateReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateReferenceImageRequest): - request = product_search_service.CreateReferenceImageRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if reference_image is not None: - request.reference_image = reference_image - if reference_image_id is not None: - request.reference_image_id = reference_image_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_reference_image] - - # 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_reference_image(self, - request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (Union[google.cloud.vision_v1.types.DeleteReferenceImageRequest, dict]): - The request object. Request message for the - `DeleteReferenceImage` method. - name (str): - Required. The resource name of the reference image to - delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - - 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. - """ - # 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 product_search_service.DeleteReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteReferenceImageRequest): - request = product_search_service.DeleteReferenceImageRequest(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_reference_image] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_reference_images(self, - request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListReferenceImagesPager: - r"""Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Args: - request (Union[google.cloud.vision_v1.types.ListReferenceImagesRequest, dict]): - The request object. Request message for the - `ListReferenceImages` method. - parent (str): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - 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.vision_v1.services.product_search.pagers.ListReferenceImagesPager: - Response message for the ListReferenceImages method. - - 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 product_search_service.ListReferenceImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListReferenceImagesRequest): - request = product_search_service.ListReferenceImagesRequest(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_reference_images] - - # 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.ListReferenceImagesPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_reference_image(self, - request: Union[product_search_service.GetReferenceImageRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Args: - request (Union[google.cloud.vision_v1.types.GetReferenceImageRequest, dict]): - The request object. Request message for the - `GetReferenceImage` method. - name (str): - Required. The resource name of the ReferenceImage to - get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - 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.vision_v1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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 product_search_service.GetReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetReferenceImageRequest): - request = product_search_service.GetReferenceImageRequest(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.get_reference_image] - - # 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 add_product_to_product_set(self, - request: Union[product_search_service.AddProductToProductSetRequest, dict] = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Args: - request (Union[google.cloud.vision_v1.types.AddProductToProductSetRequest, dict]): - The request object. Request message for the - `AddProductToProductSet` method. - name (str): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (str): - Required. The resource name for the Product to be added - to this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 product_search_service.AddProductToProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.AddProductToProductSetRequest): - request = product_search_service.AddProductToProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.add_product_to_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def remove_product_from_product_set(self, - request: Union[product_search_service.RemoveProductFromProductSetRequest, dict] = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Removes a Product from the specified ProductSet. - - Args: - request (Union[google.cloud.vision_v1.types.RemoveProductFromProductSetRequest, dict]): - The request object. Request message for the - `RemoveProductFromProductSet` method. - name (str): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (str): - Required. The resource name for the Product to be - removed from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 product_search_service.RemoveProductFromProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.RemoveProductFromProductSetRequest): - request = product_search_service.RemoveProductFromProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.remove_product_from_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_products_in_product_set(self, - request: Union[product_search_service.ListProductsInProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsInProductSetPager: - r"""Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (Union[google.cloud.vision_v1.types.ListProductsInProductSetRequest, dict]): - The request object. Request message for the - `ListProductsInProductSet` method. - name (str): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1.services.product_search.pagers.ListProductsInProductSetPager: - Response message for the ListProductsInProductSet - method. - - 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([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 product_search_service.ListProductsInProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductsInProductSetRequest): - request = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set] - - # 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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListProductsInProductSetPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def import_product_sets(self, - request: Union[product_search_service.ImportProductSetsRequest, dict] = None, - *, - parent: str = None, - input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. - - Args: - request (Union[google.cloud.vision_v1.types.ImportProductSetsRequest, dict]): - The request object. Request message for the - `ImportProductSets` method. - parent (str): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - input_config (google.cloud.vision_v1.types.ImportProductSetsInputConfig): - Required. The input content for the - list of requests. - - This corresponds to the ``input_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.vision_v1.types.ImportProductSetsResponse` - Response message for the ImportProductSets method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - """ - # 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, input_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 product_search_service.ImportProductSetsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ImportProductSetsRequest): - request = product_search_service.ImportProductSetsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if input_config is not None: - request.input_config = input_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.import_product_sets] - - # 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, - product_search_service.ImportProductSetsResponse, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - def purge_products(self, - request: Union[product_search_service.PurgeProductsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Args: - request (Union[google.cloud.vision_v1.types.PurgeProductsRequest, dict]): - The request object. Request message for the - `PurgeProducts` method. - parent (str): - Required. The project and location in which the Products - should be deleted. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.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([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 product_search_service.PurgeProductsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.PurgeProductsRequest): - request = product_search_service.PurgeProductsRequest(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.purge_products] - - # 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, - empty_pb2.Empty, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ProductSearchClient", -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py deleted file mode 100644 index 6ae241ca..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/pagers.py +++ /dev/null @@ -1,506 +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, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator - -from google.cloud.vision_v1.types import product_search_service - - -class ListProductSetsPager: - """A pager for iterating through ``list_product_sets`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListProductSetsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``product_sets`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProductSets`` requests and continue to iterate - through the ``product_sets`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListProductSetsResponse` - 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[..., product_search_service.ListProductSetsResponse], - request: product_search_service.ListProductSetsRequest, - response: product_search_service.ListProductSetsResponse, - *, - 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.vision_v1.types.ListProductSetsRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListProductSetsResponse): - 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 = product_search_service.ListProductSetsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductSetsResponse]: - 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) -> Iterator[product_search_service.ProductSet]: - for page in self.pages: - yield from page.product_sets - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductSetsAsyncPager: - """A pager for iterating through ``list_product_sets`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListProductSetsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``product_sets`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProductSets`` requests and continue to iterate - through the ``product_sets`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListProductSetsResponse` - 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[product_search_service.ListProductSetsResponse]], - request: product_search_service.ListProductSetsRequest, - response: product_search_service.ListProductSetsResponse, - *, - 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.vision_v1.types.ListProductSetsRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListProductSetsResponse): - 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 = product_search_service.ListProductSetsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductSetsResponse]: - 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) -> AsyncIterator[product_search_service.ProductSet]: - async def async_generator(): - async for page in self.pages: - for response in page.product_sets: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListProductsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListProductsResponse` - 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[..., product_search_service.ListProductsResponse], - request: product_search_service.ListProductsRequest, - response: product_search_service.ListProductsResponse, - *, - 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.vision_v1.types.ListProductsRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListProductsResponse): - 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 = product_search_service.ListProductsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductsResponse]: - 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) -> Iterator[product_search_service.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsAsyncPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListProductsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListProductsResponse` - 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[product_search_service.ListProductsResponse]], - request: product_search_service.ListProductsRequest, - response: product_search_service.ListProductsResponse, - *, - 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.vision_v1.types.ListProductsRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListProductsResponse): - 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 = product_search_service.ListProductsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductsResponse]: - 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) -> AsyncIterator[product_search_service.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListReferenceImagesPager: - """A pager for iterating through ``list_reference_images`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` object, and - provides an ``__iter__`` method to iterate through its - ``reference_images`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListReferenceImages`` requests and continue to iterate - through the ``reference_images`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` - 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[..., product_search_service.ListReferenceImagesResponse], - request: product_search_service.ListReferenceImagesRequest, - response: product_search_service.ListReferenceImagesResponse, - *, - 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.vision_v1.types.ListReferenceImagesRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListReferenceImagesResponse): - 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 = product_search_service.ListReferenceImagesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListReferenceImagesResponse]: - 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) -> Iterator[product_search_service.ReferenceImage]: - for page in self.pages: - yield from page.reference_images - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListReferenceImagesAsyncPager: - """A pager for iterating through ``list_reference_images`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``reference_images`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListReferenceImages`` requests and continue to iterate - through the ``reference_images`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListReferenceImagesResponse` - 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[product_search_service.ListReferenceImagesResponse]], - request: product_search_service.ListReferenceImagesRequest, - response: product_search_service.ListReferenceImagesResponse, - *, - 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.vision_v1.types.ListReferenceImagesRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListReferenceImagesResponse): - 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 = product_search_service.ListReferenceImagesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListReferenceImagesResponse]: - 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) -> AsyncIterator[product_search_service.ReferenceImage]: - async def async_generator(): - async for page in self.pages: - for response in page.reference_images: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsInProductSetPager: - """A pager for iterating through ``list_products_in_product_set`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProductsInProductSet`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` - 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[..., product_search_service.ListProductsInProductSetResponse], - request: product_search_service.ListProductsInProductSetRequest, - response: product_search_service.ListProductsInProductSetResponse, - *, - 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.vision_v1.types.ListProductsInProductSetRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListProductsInProductSetResponse): - 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 = product_search_service.ListProductsInProductSetRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductsInProductSetResponse]: - 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) -> Iterator[product_search_service.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsInProductSetAsyncPager: - """A pager for iterating through ``list_products_in_product_set`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProductsInProductSet`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1.types.ListProductsInProductSetResponse` - 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[product_search_service.ListProductsInProductSetResponse]], - request: product_search_service.ListProductsInProductSetRequest, - response: product_search_service.ListProductsInProductSetResponse, - *, - 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.vision_v1.types.ListProductsInProductSetRequest): - The initial request object. - response (google.cloud.vision_v1.types.ListProductsInProductSetResponse): - 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 = product_search_service.ListProductsInProductSetRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductsInProductSetResponse]: - 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) -> AsyncIterator[product_search_service.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - 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/v1/google/cloud/vision_v1/services/product_search/transports/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/__init__.py deleted file mode 100644 index 22b20282..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/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 ProductSearchTransport -from .grpc import ProductSearchGrpcTransport -from .grpc_asyncio import ProductSearchGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ProductSearchTransport]] -_transport_registry['grpc'] = ProductSearchGrpcTransport -_transport_registry['grpc_asyncio'] = ProductSearchGrpcAsyncIOTransport - -__all__ = ( - 'ProductSearchTransport', - 'ProductSearchGrpcTransport', - 'ProductSearchGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py deleted file mode 100644 index eb6258c0..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/base.py +++ /dev/null @@ -1,561 +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.vision_v1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-vision', - ).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 ProductSearchTransport(abc.ABC): - """Abstract transport class for ProductSearch.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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.create_product_set: gapic_v1.method.wrap_method( - self.create_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_product_sets: gapic_v1.method.wrap_method( - self.list_product_sets, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_product_set: gapic_v1.method.wrap_method( - self.get_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.update_product_set: gapic_v1.method.wrap_method( - self.update_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_product_set: gapic_v1.method.wrap_method( - self.delete_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.create_product: gapic_v1.method.wrap_method( - self.create_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_products: gapic_v1.method.wrap_method( - self.list_products, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_product: gapic_v1.method.wrap_method( - self.get_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.update_product: gapic_v1.method.wrap_method( - self.update_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_product: gapic_v1.method.wrap_method( - self.delete_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.create_reference_image: gapic_v1.method.wrap_method( - self.create_reference_image, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_reference_image: gapic_v1.method.wrap_method( - self.delete_reference_image, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_reference_images: gapic_v1.method.wrap_method( - self.list_reference_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_reference_image: gapic_v1.method.wrap_method( - self.get_reference_image, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.add_product_to_product_set: gapic_v1.method.wrap_method( - self.add_product_to_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.remove_product_from_product_set: gapic_v1.method.wrap_method( - self.remove_product_from_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_products_in_product_set: gapic_v1.method.wrap_method( - self.list_products_in_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.import_product_sets: gapic_v1.method.wrap_method( - self.import_product_sets, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.purge_products: gapic_v1.method.wrap_method( - self.purge_products, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - Union[ - product_search_service.ListProductSetsResponse, - Awaitable[product_search_service.ListProductSetsResponse] - ]]: - raise NotImplementedError() - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - Union[ - product_search_service.ListProductsResponse, - Awaitable[product_search_service.ListProductsResponse] - ]]: - raise NotImplementedError() - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - Union[ - product_search_service.ReferenceImage, - Awaitable[product_search_service.ReferenceImage] - ]]: - raise NotImplementedError() - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - Union[ - product_search_service.ListReferenceImagesResponse, - Awaitable[product_search_service.ListReferenceImagesResponse] - ]]: - raise NotImplementedError() - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - Union[ - product_search_service.ReferenceImage, - Awaitable[product_search_service.ReferenceImage] - ]]: - raise NotImplementedError() - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - Union[ - product_search_service.ListProductsInProductSetResponse, - Awaitable[product_search_service.ListProductsInProductSetResponse] - ]]: - raise NotImplementedError() - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def purge_products(self) -> Callable[ - [product_search_service.PurgeProductsRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ProductSearchTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py deleted file mode 100644 index d84f625f..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc.py +++ /dev/null @@ -1,912 +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.vision_v1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO - - -class ProductSearchGrpcTransport(ProductSearchTransport): - """gRPC backend transport for ProductSearch. - - Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1.Product] has a collection - of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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 create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the create product set method over gRPC. - - Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Returns: - Callable[[~.CreateProductSetRequest], - ~.ProductSet]: - 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_product_set' not in self._stubs: - self._stubs['create_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/CreateProductSet', - request_serializer=product_search_service.CreateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['create_product_set'] - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - product_search_service.ListProductSetsResponse]: - r"""Return a callable for the list product sets method over gRPC. - - Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Returns: - Callable[[~.ListProductSetsRequest], - ~.ListProductSetsResponse]: - 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_product_sets' not in self._stubs: - self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListProductSets', - request_serializer=product_search_service.ListProductSetsRequest.serialize, - response_deserializer=product_search_service.ListProductSetsResponse.deserialize, - ) - return self._stubs['list_product_sets'] - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the get product set method over gRPC. - - Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.GetProductSetRequest], - ~.ProductSet]: - 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 'get_product_set' not in self._stubs: - self._stubs['get_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/GetProductSet', - request_serializer=product_search_service.GetProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['get_product_set'] - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the update product set method over gRPC. - - Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Returns: - Callable[[~.UpdateProductSetRequest], - ~.ProductSet]: - 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 'update_product_set' not in self._stubs: - self._stubs['update_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/UpdateProductSet', - request_serializer=product_search_service.UpdateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['update_product_set'] - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product set method over gRPC. - - Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteProductSetRequest], - ~.Empty]: - 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_product_set' not in self._stubs: - self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/DeleteProductSet', - request_serializer=product_search_service.DeleteProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_set'] - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - product_search_service.Product]: - r"""Return a callable for the create product method over gRPC. - - Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Returns: - Callable[[~.CreateProductRequest], - ~.Product]: - 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_product' not in self._stubs: - self._stubs['create_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/CreateProduct', - request_serializer=product_search_service.CreateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['create_product'] - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - product_search_service.ListProductsResponse]: - r"""Return a callable for the list products method over gRPC. - - Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsRequest], - ~.ListProductsResponse]: - 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_products' not in self._stubs: - self._stubs['list_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListProducts', - request_serializer=product_search_service.ListProductsRequest.serialize, - response_deserializer=product_search_service.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - product_search_service.Product]: - r"""Return a callable for the get product method over gRPC. - - Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns: - Callable[[~.GetProductRequest], - ~.Product]: - 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 'get_product' not in self._stubs: - self._stubs['get_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/GetProduct', - request_serializer=product_search_service.GetProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - product_search_service.Product]: - r"""Return a callable for the update product method over gRPC. - - Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Returns: - Callable[[~.UpdateProductRequest], - ~.Product]: - 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 'update_product' not in self._stubs: - self._stubs['update_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/UpdateProduct', - request_serializer=product_search_service.UpdateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['update_product'] - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product method over gRPC. - - Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Returns: - Callable[[~.DeleteProductRequest], - ~.Empty]: - 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_product' not in self._stubs: - self._stubs['delete_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/DeleteProduct', - request_serializer=product_search_service.DeleteProductRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product'] - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - product_search_service.ReferenceImage]: - r"""Return a callable for the create reference image method over gRPC. - - Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Returns: - Callable[[~.CreateReferenceImageRequest], - ~.ReferenceImage]: - 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_reference_image' not in self._stubs: - self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/CreateReferenceImage', - request_serializer=product_search_service.CreateReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['create_reference_image'] - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete reference image method over gRPC. - - Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteReferenceImageRequest], - ~.Empty]: - 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_reference_image' not in self._stubs: - self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/DeleteReferenceImage', - request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_reference_image'] - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - product_search_service.ListReferenceImagesResponse]: - r"""Return a callable for the list reference images method over gRPC. - - Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Returns: - Callable[[~.ListReferenceImagesRequest], - ~.ListReferenceImagesResponse]: - 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_reference_images' not in self._stubs: - self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListReferenceImages', - request_serializer=product_search_service.ListReferenceImagesRequest.serialize, - response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, - ) - return self._stubs['list_reference_images'] - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - product_search_service.ReferenceImage]: - r"""Return a callable for the get reference image method over gRPC. - - Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Returns: - Callable[[~.GetReferenceImageRequest], - ~.ReferenceImage]: - 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 'get_reference_image' not in self._stubs: - self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/GetReferenceImage', - request_serializer=product_search_service.GetReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['get_reference_image'] - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the add product to product set method over gRPC. - - Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Returns: - Callable[[~.AddProductToProductSetRequest], - ~.Empty]: - 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 'add_product_to_product_set' not in self._stubs: - self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/AddProductToProductSet', - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['add_product_to_product_set'] - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the remove product from product - set method over gRPC. - - Removes a Product from the specified ProductSet. - - Returns: - Callable[[~.RemoveProductFromProductSetRequest], - ~.Empty]: - 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 'remove_product_from_product_set' not in self._stubs: - self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet', - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['remove_product_from_product_set'] - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - product_search_service.ListProductsInProductSetResponse]: - r"""Return a callable for the list products in product set method over gRPC. - - Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsInProductSetRequest], - ~.ListProductsInProductSetResponse]: - 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_products_in_product_set' not in self._stubs: - self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet', - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, - ) - return self._stubs['list_products_in_product_set'] - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - operations_pb2.Operation]: - r"""Return a callable for the import product sets method over gRPC. - - Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. - - Returns: - Callable[[~.ImportProductSetsRequest], - ~.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 'import_product_sets' not in self._stubs: - self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ImportProductSets', - request_serializer=product_search_service.ImportProductSetsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['import_product_sets'] - - @property - def purge_products(self) -> Callable[ - [product_search_service.PurgeProductsRequest], - operations_pb2.Operation]: - r"""Return a callable for the purge products method over gRPC. - - Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Returns: - Callable[[~.PurgeProductsRequest], - ~.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 'purge_products' not in self._stubs: - self._stubs['purge_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/PurgeProducts', - request_serializer=product_search_service.PurgeProductsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['purge_products'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ProductSearchGrpcTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py b/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py deleted file mode 100644 index 95a951f5..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py +++ /dev/null @@ -1,917 +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.vision_v1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .grpc import ProductSearchGrpcTransport - - -class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): - """gRPC AsyncIO backend transport for ProductSearch. - - Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1.ProductSet] resources, named - ``projects/*/locations/*/productSets/*``, which acts as a way to - put different products into groups to limit identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1.Product] has a collection - of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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 create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the create product set method over gRPC. - - Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Returns: - Callable[[~.CreateProductSetRequest], - Awaitable[~.ProductSet]]: - 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_product_set' not in self._stubs: - self._stubs['create_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/CreateProductSet', - request_serializer=product_search_service.CreateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['create_product_set'] - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - Awaitable[product_search_service.ListProductSetsResponse]]: - r"""Return a callable for the list product sets method over gRPC. - - Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Returns: - Callable[[~.ListProductSetsRequest], - Awaitable[~.ListProductSetsResponse]]: - 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_product_sets' not in self._stubs: - self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListProductSets', - request_serializer=product_search_service.ListProductSetsRequest.serialize, - response_deserializer=product_search_service.ListProductSetsResponse.deserialize, - ) - return self._stubs['list_product_sets'] - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the get product set method over gRPC. - - Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.GetProductSetRequest], - Awaitable[~.ProductSet]]: - 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 'get_product_set' not in self._stubs: - self._stubs['get_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/GetProductSet', - request_serializer=product_search_service.GetProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['get_product_set'] - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the update product set method over gRPC. - - Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Returns: - Callable[[~.UpdateProductSetRequest], - Awaitable[~.ProductSet]]: - 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 'update_product_set' not in self._stubs: - self._stubs['update_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/UpdateProductSet', - request_serializer=product_search_service.UpdateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['update_product_set'] - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product set method over gRPC. - - Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteProductSetRequest], - Awaitable[~.Empty]]: - 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_product_set' not in self._stubs: - self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/DeleteProductSet', - request_serializer=product_search_service.DeleteProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_set'] - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the create product method over gRPC. - - Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Returns: - Callable[[~.CreateProductRequest], - Awaitable[~.Product]]: - 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_product' not in self._stubs: - self._stubs['create_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/CreateProduct', - request_serializer=product_search_service.CreateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['create_product'] - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - Awaitable[product_search_service.ListProductsResponse]]: - r"""Return a callable for the list products method over gRPC. - - Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsRequest], - Awaitable[~.ListProductsResponse]]: - 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_products' not in self._stubs: - self._stubs['list_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListProducts', - request_serializer=product_search_service.ListProductsRequest.serialize, - response_deserializer=product_search_service.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the get product method over gRPC. - - Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns: - Callable[[~.GetProductRequest], - Awaitable[~.Product]]: - 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 'get_product' not in self._stubs: - self._stubs['get_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/GetProduct', - request_serializer=product_search_service.GetProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the update product method over gRPC. - - Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Returns: - Callable[[~.UpdateProductRequest], - Awaitable[~.Product]]: - 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 'update_product' not in self._stubs: - self._stubs['update_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/UpdateProduct', - request_serializer=product_search_service.UpdateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['update_product'] - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product method over gRPC. - - Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Returns: - Callable[[~.DeleteProductRequest], - Awaitable[~.Empty]]: - 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_product' not in self._stubs: - self._stubs['delete_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/DeleteProduct', - request_serializer=product_search_service.DeleteProductRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product'] - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - Awaitable[product_search_service.ReferenceImage]]: - r"""Return a callable for the create reference image method over gRPC. - - Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Returns: - Callable[[~.CreateReferenceImageRequest], - Awaitable[~.ReferenceImage]]: - 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_reference_image' not in self._stubs: - self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/CreateReferenceImage', - request_serializer=product_search_service.CreateReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['create_reference_image'] - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete reference image method over gRPC. - - Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteReferenceImageRequest], - Awaitable[~.Empty]]: - 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_reference_image' not in self._stubs: - self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/DeleteReferenceImage', - request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_reference_image'] - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - Awaitable[product_search_service.ListReferenceImagesResponse]]: - r"""Return a callable for the list reference images method over gRPC. - - Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Returns: - Callable[[~.ListReferenceImagesRequest], - Awaitable[~.ListReferenceImagesResponse]]: - 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_reference_images' not in self._stubs: - self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListReferenceImages', - request_serializer=product_search_service.ListReferenceImagesRequest.serialize, - response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, - ) - return self._stubs['list_reference_images'] - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - Awaitable[product_search_service.ReferenceImage]]: - r"""Return a callable for the get reference image method over gRPC. - - Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Returns: - Callable[[~.GetReferenceImageRequest], - Awaitable[~.ReferenceImage]]: - 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 'get_reference_image' not in self._stubs: - self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/GetReferenceImage', - request_serializer=product_search_service.GetReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['get_reference_image'] - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the add product to product set method over gRPC. - - Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Returns: - Callable[[~.AddProductToProductSetRequest], - Awaitable[~.Empty]]: - 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 'add_product_to_product_set' not in self._stubs: - self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/AddProductToProductSet', - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['add_product_to_product_set'] - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the remove product from product - set method over gRPC. - - Removes a Product from the specified ProductSet. - - Returns: - Callable[[~.RemoveProductFromProductSetRequest], - Awaitable[~.Empty]]: - 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 'remove_product_from_product_set' not in self._stubs: - self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet', - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['remove_product_from_product_set'] - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - Awaitable[product_search_service.ListProductsInProductSetResponse]]: - r"""Return a callable for the list products in product set method over gRPC. - - Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsInProductSetRequest], - Awaitable[~.ListProductsInProductSetResponse]]: - 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_products_in_product_set' not in self._stubs: - self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ListProductsInProductSet', - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, - ) - return self._stubs['list_products_in_product_set'] - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the import product sets method over gRPC. - - Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. - - Returns: - Callable[[~.ImportProductSetsRequest], - 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 'import_product_sets' not in self._stubs: - self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/ImportProductSets', - request_serializer=product_search_service.ImportProductSetsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['import_product_sets'] - - @property - def purge_products(self) -> Callable[ - [product_search_service.PurgeProductsRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the purge products method over gRPC. - - Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Returns: - Callable[[~.PurgeProductsRequest], - 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 'purge_products' not in self._stubs: - self._stubs['purge_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1.ProductSearch/PurgeProducts', - request_serializer=product_search_service.PurgeProductsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['purge_products'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ProductSearchGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py deleted file mode 100644 index c652d4b2..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/__init__.py +++ /dev/null @@ -1,198 +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 .geometry import ( - BoundingPoly, - NormalizedVertex, - Position, - Vertex, -) -from .image_annotator import ( - AnnotateFileRequest, - AnnotateFileResponse, - AnnotateImageRequest, - AnnotateImageResponse, - AsyncAnnotateFileRequest, - AsyncAnnotateFileResponse, - AsyncBatchAnnotateFilesRequest, - AsyncBatchAnnotateFilesResponse, - AsyncBatchAnnotateImagesRequest, - AsyncBatchAnnotateImagesResponse, - BatchAnnotateFilesRequest, - BatchAnnotateFilesResponse, - BatchAnnotateImagesRequest, - BatchAnnotateImagesResponse, - ColorInfo, - CropHint, - CropHintsAnnotation, - CropHintsParams, - DominantColorsAnnotation, - EntityAnnotation, - FaceAnnotation, - Feature, - GcsDestination, - GcsSource, - Image, - ImageAnnotationContext, - ImageContext, - ImageProperties, - ImageSource, - InputConfig, - LatLongRect, - LocalizedObjectAnnotation, - LocationInfo, - OperationMetadata, - OutputConfig, - Property, - SafeSearchAnnotation, - TextDetectionParams, - WebDetectionParams, - Likelihood, -) -from .product_search import ( - ProductSearchParams, - ProductSearchResults, -) -from .product_search_service import ( - AddProductToProductSetRequest, - BatchOperationMetadata, - CreateProductRequest, - CreateProductSetRequest, - CreateReferenceImageRequest, - DeleteProductRequest, - DeleteProductSetRequest, - DeleteReferenceImageRequest, - GetProductRequest, - GetProductSetRequest, - GetReferenceImageRequest, - ImportProductSetsGcsSource, - ImportProductSetsInputConfig, - ImportProductSetsRequest, - ImportProductSetsResponse, - ListProductSetsRequest, - ListProductSetsResponse, - ListProductsInProductSetRequest, - ListProductsInProductSetResponse, - ListProductsRequest, - ListProductsResponse, - ListReferenceImagesRequest, - ListReferenceImagesResponse, - Product, - ProductSet, - ProductSetPurgeConfig, - PurgeProductsRequest, - ReferenceImage, - RemoveProductFromProductSetRequest, - UpdateProductRequest, - UpdateProductSetRequest, -) -from .text_annotation import ( - Block, - Page, - Paragraph, - Symbol, - TextAnnotation, - Word, -) -from .web_detection import ( - WebDetection, -) - -__all__ = ( - 'BoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileRequest', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'AsyncBatchAnnotateImagesRequest', - 'AsyncBatchAnnotateImagesResponse', - 'BatchAnnotateFilesRequest', - 'BatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocalizedObjectAnnotation', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'ProductSearchParams', - 'ProductSearchResults', - 'AddProductToProductSetRequest', - 'BatchOperationMetadata', - 'CreateProductRequest', - 'CreateProductSetRequest', - 'CreateReferenceImageRequest', - 'DeleteProductRequest', - 'DeleteProductSetRequest', - 'DeleteReferenceImageRequest', - 'GetProductRequest', - 'GetProductSetRequest', - 'GetReferenceImageRequest', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ListProductsRequest', - 'ListProductsResponse', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'Product', - 'ProductSet', - 'ProductSetPurgeConfig', - 'PurgeProductsRequest', - 'ReferenceImage', - 'RemoveProductFromProductSetRequest', - 'UpdateProductRequest', - 'UpdateProductSetRequest', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py deleted file mode 100644 index f938d235..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/geometry.py +++ /dev/null @@ -1,125 +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.vision.v1', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - 'Position', - }, -) - - -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.vision_v1.types.Vertex]): - The bounding polygon vertices. - normalized_vertices (Sequence[google.cloud.vision_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', - ) - - -class Position(proto.Message): - r"""A 3D position in the image, used primarily for Face detection - landmarks. A valid Position must have both x and y coordinates. - The position coordinates are in the same scale as the original - image. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate. - z (float): - Z coordinate (or depth). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - z = proto.Field( - proto.FLOAT, - number=3, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py deleted file mode 100644 index a5e7fc0b..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/image_annotator.py +++ /dev/null @@ -1,1612 +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.vision_v1.types import geometry -from google.cloud.vision_v1.types import product_search -from google.cloud.vision_v1.types import text_annotation -from google.cloud.vision_v1.types import web_detection as gcv_web_detection -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 latlng_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1', - manifest={ - 'Likelihood', - 'Feature', - 'ImageSource', - 'Image', - 'FaceAnnotation', - 'LocationInfo', - 'Property', - 'EntityAnnotation', - 'LocalizedObjectAnnotation', - 'SafeSearchAnnotation', - 'LatLongRect', - 'ColorInfo', - 'DominantColorsAnnotation', - 'ImageProperties', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'WebDetectionParams', - 'TextDetectionParams', - 'ImageContext', - 'AnnotateImageRequest', - 'ImageAnnotationContext', - 'AnnotateImageResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'AnnotateFileRequest', - 'AnnotateFileResponse', - 'BatchAnnotateFilesRequest', - 'BatchAnnotateFilesResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateImagesRequest', - 'AsyncBatchAnnotateImagesResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'InputConfig', - 'OutputConfig', - 'GcsSource', - 'GcsDestination', - 'OperationMetadata', - }, -) - - -class Likelihood(proto.Enum): - r"""A bucketized representation of likelihood, which is intended - to give clients highly stable results across model upgrades. - """ - UNKNOWN = 0 - VERY_UNLIKELY = 1 - UNLIKELY = 2 - POSSIBLE = 3 - LIKELY = 4 - VERY_LIKELY = 5 - - -class Feature(proto.Message): - r"""The type of Google Cloud Vision API detection to perform, and the - maximum number of results to return for that type. Multiple - ``Feature`` objects can be specified in the ``features`` list. - - Attributes: - type_ (google.cloud.vision_v1.types.Feature.Type): - The feature type. - max_results (int): - Maximum number of results of this type. Does not apply to - ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or - ``CROP_HINTS``. - model (str): - Model to use for the feature. - Supported values: "builtin/stable" (the default - if unset) and "builtin/latest". - """ - class Type(proto.Enum): - r"""Type of Google Cloud Vision API feature to be extracted.""" - TYPE_UNSPECIFIED = 0 - FACE_DETECTION = 1 - LANDMARK_DETECTION = 2 - LOGO_DETECTION = 3 - LABEL_DETECTION = 4 - TEXT_DETECTION = 5 - DOCUMENT_TEXT_DETECTION = 11 - SAFE_SEARCH_DETECTION = 6 - IMAGE_PROPERTIES = 7 - CROP_HINTS = 9 - WEB_DETECTION = 10 - PRODUCT_SEARCH = 12 - OBJECT_LOCALIZATION = 19 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum=Type, - ) - max_results = proto.Field( - proto.INT32, - number=2, - ) - model = proto.Field( - proto.STRING, - number=3, - ) - - -class ImageSource(proto.Message): - r"""External image source (Google Cloud Storage or web URL image - location). - - Attributes: - gcs_image_uri (str): - **Use ``image_uri`` instead.** - - The 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. - image_uri (str): - The URI of the source image. Can be either: - - 1. A 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. - - 2. A publicly-accessible image HTTP/HTTPS URL. When fetching - images from HTTP/HTTPS URLs, Google cannot guarantee that - the request will be completed. Your request may fail if - the specified host denies the request (e.g. due to - request throttling or DOS prevention), or if Google - throttles requests to the site for abuse prevention. You - should not depend on externally-hosted images for - production applications. - - When both ``gcs_image_uri`` and ``image_uri`` are specified, - ``image_uri`` takes precedence. - """ - - gcs_image_uri = proto.Field( - proto.STRING, - number=1, - ) - image_uri = proto.Field( - proto.STRING, - number=2, - ) - - -class Image(proto.Message): - r"""Client image to perform Google Cloud Vision API tasks over. - - Attributes: - content (bytes): - Image content, represented as a stream of bytes. Note: As - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - - Currently, this field only works for BatchAnnotateImages - requests. It does not work for AsyncBatchAnnotateImages - requests. - source (google.cloud.vision_v1.types.ImageSource): - Google Cloud Storage image location, or publicly-accessible - image URL. If both ``content`` and ``source`` are provided - for an image, ``content`` takes precedence and is used to - perform the image annotation request. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - source = proto.Field( - proto.MESSAGE, - number=2, - message='ImageSource', - ) - - -class FaceAnnotation(proto.Message): - r"""A face annotation object contains the results of face - detection. - - Attributes: - bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - The bounding polygon around the face. The coordinates of the - bounding box are in the original image's scale. The bounding - box is computed to "frame" the face in accordance with human - expectations. It is based on the landmarker results. Note - that one or more x and/or y coordinates may not be generated - in the ``BoundingPoly`` (the polygon will be unbounded) if - only a partial face appears in the image to be annotated. - fd_bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - The ``fd_bounding_poly`` bounding polygon is tighter than - the ``boundingPoly``, and encloses only the skin part of the - face. Typically, it is used to eliminate the face from any - image analysis that detects the "amount of skin" visible in - an image. It is not based on the landmarker results, only on - the initial face detection, hence the fd (face detection) - prefix. - landmarks (Sequence[google.cloud.vision_v1.types.FaceAnnotation.Landmark]): - Detected face landmarks. - roll_angle (float): - Roll angle, which indicates the amount of - clockwise/anti-clockwise rotation of the face relative to - the image vertical about the axis perpendicular to the face. - Range [-180,180]. - pan_angle (float): - Yaw angle, which indicates the leftward/rightward angle that - the face is pointing relative to the vertical plane - perpendicular to the image. Range [-180,180]. - tilt_angle (float): - Pitch angle, which indicates the upwards/downwards angle - that the face is pointing relative to the image's horizontal - plane. Range [-180,180]. - detection_confidence (float): - Detection confidence. Range [0, 1]. - landmarking_confidence (float): - Face landmarking confidence. Range [0, 1]. - joy_likelihood (google.cloud.vision_v1.types.Likelihood): - Joy likelihood. - sorrow_likelihood (google.cloud.vision_v1.types.Likelihood): - Sorrow likelihood. - anger_likelihood (google.cloud.vision_v1.types.Likelihood): - Anger likelihood. - surprise_likelihood (google.cloud.vision_v1.types.Likelihood): - Surprise likelihood. - under_exposed_likelihood (google.cloud.vision_v1.types.Likelihood): - Under-exposed likelihood. - blurred_likelihood (google.cloud.vision_v1.types.Likelihood): - Blurred likelihood. - headwear_likelihood (google.cloud.vision_v1.types.Likelihood): - Headwear likelihood. - """ - - class Landmark(proto.Message): - r"""A face-specific landmark (for example, a face feature). - - Attributes: - type_ (google.cloud.vision_v1.types.FaceAnnotation.Landmark.Type): - Face landmark type. - position (google.cloud.vision_v1.types.Position): - Face landmark position. - """ - class Type(proto.Enum): - r"""Face landmark (feature) type. Left and right are defined from the - vantage of the viewer of the image without considering mirror - projections typical of photos. So, ``LEFT_EYE``, typically, is the - person's right eye. - """ - UNKNOWN_LANDMARK = 0 - LEFT_EYE = 1 - RIGHT_EYE = 2 - LEFT_OF_LEFT_EYEBROW = 3 - RIGHT_OF_LEFT_EYEBROW = 4 - LEFT_OF_RIGHT_EYEBROW = 5 - RIGHT_OF_RIGHT_EYEBROW = 6 - MIDPOINT_BETWEEN_EYES = 7 - NOSE_TIP = 8 - UPPER_LIP = 9 - LOWER_LIP = 10 - MOUTH_LEFT = 11 - MOUTH_RIGHT = 12 - MOUTH_CENTER = 13 - NOSE_BOTTOM_RIGHT = 14 - NOSE_BOTTOM_LEFT = 15 - NOSE_BOTTOM_CENTER = 16 - LEFT_EYE_TOP_BOUNDARY = 17 - LEFT_EYE_RIGHT_CORNER = 18 - LEFT_EYE_BOTTOM_BOUNDARY = 19 - LEFT_EYE_LEFT_CORNER = 20 - RIGHT_EYE_TOP_BOUNDARY = 21 - RIGHT_EYE_RIGHT_CORNER = 22 - RIGHT_EYE_BOTTOM_BOUNDARY = 23 - RIGHT_EYE_LEFT_CORNER = 24 - LEFT_EYEBROW_UPPER_MIDPOINT = 25 - RIGHT_EYEBROW_UPPER_MIDPOINT = 26 - LEFT_EAR_TRAGION = 27 - RIGHT_EAR_TRAGION = 28 - LEFT_EYE_PUPIL = 29 - RIGHT_EYE_PUPIL = 30 - FOREHEAD_GLABELLA = 31 - CHIN_GNATHION = 32 - CHIN_LEFT_GONION = 33 - CHIN_RIGHT_GONION = 34 - LEFT_CHEEK_CENTER = 35 - RIGHT_CHEEK_CENTER = 36 - - type_ = proto.Field( - proto.ENUM, - number=3, - enum='FaceAnnotation.Landmark.Type', - ) - position = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.Position, - ) - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - fd_bounding_poly = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - landmarks = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=Landmark, - ) - roll_angle = proto.Field( - proto.FLOAT, - number=4, - ) - pan_angle = proto.Field( - proto.FLOAT, - number=5, - ) - tilt_angle = proto.Field( - proto.FLOAT, - number=6, - ) - detection_confidence = proto.Field( - proto.FLOAT, - number=7, - ) - landmarking_confidence = proto.Field( - proto.FLOAT, - number=8, - ) - joy_likelihood = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - sorrow_likelihood = proto.Field( - proto.ENUM, - number=10, - enum='Likelihood', - ) - anger_likelihood = proto.Field( - proto.ENUM, - number=11, - enum='Likelihood', - ) - surprise_likelihood = proto.Field( - proto.ENUM, - number=12, - enum='Likelihood', - ) - under_exposed_likelihood = proto.Field( - proto.ENUM, - number=13, - enum='Likelihood', - ) - blurred_likelihood = proto.Field( - proto.ENUM, - number=14, - enum='Likelihood', - ) - headwear_likelihood = proto.Field( - proto.ENUM, - number=15, - enum='Likelihood', - ) - - -class LocationInfo(proto.Message): - r"""Detected entity location information. - - Attributes: - lat_lng (google.type.latlng_pb2.LatLng): - lat/long location coordinates. - """ - - lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - - -class Property(proto.Message): - r"""A ``Property`` consists of a user-supplied name/value pair. - - Attributes: - name (str): - Name of the property. - value (str): - Value of the property. - uint64_value (int): - Value of numeric properties. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - uint64_value = proto.Field( - proto.UINT64, - number=3, - ) - - -class EntityAnnotation(proto.Message): - r"""Set of detected entity features. - - Attributes: - mid (str): - Opaque entity ID. Some IDs may be available in `Google - Knowledge Graph Search - API `__. - locale (str): - The language code for the locale in which the entity textual - ``description`` is expressed. - description (str): - Entity textual description, expressed in its ``locale`` - language. - score (float): - Overall score of the result. Range [0, 1]. - confidence (float): - **Deprecated. Use ``score`` instead.** The accuracy of the - entity detection in an image. For example, for an image in - which the "Eiffel Tower" entity is detected, this field - represents the confidence that there is a tower in the query - image. Range [0, 1]. - topicality (float): - The relevancy of the ICA (Image Content Annotation) label to - the image. For example, the relevancy of "tower" is likely - higher to an image containing the detected "Eiffel Tower" - than to an image containing a detected distant towering - building, even though the confidence that there is a tower - in each image may be the same. Range [0, 1]. - bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - Image region to which this entity belongs. Not produced for - ``LABEL_DETECTION`` features. - locations (Sequence[google.cloud.vision_v1.types.LocationInfo]): - The location information for the detected entity. Multiple - ``LocationInfo`` elements can be present because one - location may indicate the location of the scene in the - image, and another location may indicate the location of the - place where the image was taken. Location information is - usually present for landmarks. - properties (Sequence[google.cloud.vision_v1.types.Property]): - Some entities may have optional user-supplied ``Property`` - (name/value) fields, such a score or string that qualifies - the entity. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - locale = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - topicality = proto.Field( - proto.FLOAT, - number=6, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=7, - message=geometry.BoundingPoly, - ) - locations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='LocationInfo', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Property', - ) - - -class LocalizedObjectAnnotation(proto.Message): - r"""Set of detected objects with bounding boxes. - - Attributes: - mid (str): - Object ID that should align with - EntityAnnotation mid. - 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. - name (str): - Object name, expressed in its ``language_code`` language. - score (float): - Score of the result. Range [0, 1]. - bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - Image region to which this object belongs. - This must be populated. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - name = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=5, - message=geometry.BoundingPoly, - ) - - -class SafeSearchAnnotation(proto.Message): - r"""Set of features pertaining to the image, computed by computer - vision methods over safe-search verticals (for example, adult, - spoof, medical, violence). - - Attributes: - adult (google.cloud.vision_v1.types.Likelihood): - Represents the adult content likelihood for - the image. Adult content may contain elements - such as nudity, pornographic images or cartoons, - or sexual activities. - spoof (google.cloud.vision_v1.types.Likelihood): - Spoof likelihood. The likelihood that an - modification was made to the image's canonical - version to make it appear funny or offensive. - medical (google.cloud.vision_v1.types.Likelihood): - Likelihood that this is a medical image. - violence (google.cloud.vision_v1.types.Likelihood): - Likelihood that this image contains violent - content. - racy (google.cloud.vision_v1.types.Likelihood): - Likelihood that the request image contains - racy content. Racy content may include (but is - not limited to) skimpy or sheer clothing, - strategically covered nudity, lewd or - provocative poses, or close-ups of sensitive - body areas. - adult_confidence (float): - Confidence of adult_score. Range [0, 1]. 0 means not - confident, 1 means very confident. - spoof_confidence (float): - Confidence of spoof_score. Range [0, 1]. 0 means not - confident, 1 means very confident. - medical_confidence (float): - Confidence of medical_score. Range [0, 1]. 0 means not - confident, 1 means very confident. - violence_confidence (float): - Confidence of violence_score. Range [0, 1]. 0 means not - confident, 1 means very confident. - racy_confidence (float): - Confidence of racy_score. Range [0, 1]. 0 means not - confident, 1 means very confident. - nsfw_confidence (float): - Confidence of nsfw_score. Range [0, 1]. 0 means not - confident, 1 means very confident. - """ - - adult = proto.Field( - proto.ENUM, - number=1, - enum='Likelihood', - ) - spoof = proto.Field( - proto.ENUM, - number=2, - enum='Likelihood', - ) - medical = proto.Field( - proto.ENUM, - number=3, - enum='Likelihood', - ) - violence = proto.Field( - proto.ENUM, - number=4, - enum='Likelihood', - ) - racy = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - adult_confidence = proto.Field( - proto.FLOAT, - number=16, - ) - spoof_confidence = proto.Field( - proto.FLOAT, - number=18, - ) - medical_confidence = proto.Field( - proto.FLOAT, - number=20, - ) - violence_confidence = proto.Field( - proto.FLOAT, - number=22, - ) - racy_confidence = proto.Field( - proto.FLOAT, - number=24, - ) - nsfw_confidence = proto.Field( - proto.FLOAT, - number=26, - ) - - -class LatLongRect(proto.Message): - r"""Rectangle determined by min and max ``LatLng`` pairs. - - Attributes: - min_lat_lng (google.type.latlng_pb2.LatLng): - Min lat/long pair. - max_lat_lng (google.type.latlng_pb2.LatLng): - Max lat/long pair. - """ - - min_lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - max_lat_lng = proto.Field( - proto.MESSAGE, - number=2, - message=latlng_pb2.LatLng, - ) - - -class ColorInfo(proto.Message): - r"""Color information consists of RGB channels, score, and the - fraction of the image that the color occupies in the image. - - Attributes: - color (google.type.color_pb2.Color): - RGB components of the color. - score (float): - Image-specific score for this color. Value in range [0, 1]. - pixel_fraction (float): - The fraction of pixels the color occupies in the image. - Value in range [0, 1]. - """ - - color = proto.Field( - proto.MESSAGE, - number=1, - message=color_pb2.Color, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - pixel_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class DominantColorsAnnotation(proto.Message): - r"""Set of dominant colors and their corresponding scores. - - Attributes: - colors (Sequence[google.cloud.vision_v1.types.ColorInfo]): - RGB color values with their score and pixel - fraction. - """ - - colors = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ColorInfo', - ) - - -class ImageProperties(proto.Message): - r"""Stores image properties, such as dominant colors. - - Attributes: - dominant_colors (google.cloud.vision_v1.types.DominantColorsAnnotation): - If present, dominant colors completed - successfully. - """ - - dominant_colors = proto.Field( - proto.MESSAGE, - number=1, - message='DominantColorsAnnotation', - ) - - -class CropHint(proto.Message): - r"""Single crop hint that is used to generate a new crop when - serving an image. - - Attributes: - bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - The bounding polygon for the crop region. The - coordinates of the bounding box are in the - original image's scale. - confidence (float): - Confidence of this being a salient region. Range [0, 1]. - importance_fraction (float): - Fraction of importance of this salient region - with respect to the original image. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - importance_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class CropHintsAnnotation(proto.Message): - r"""Set of crop hints that are used to generate new crops when - serving images. - - Attributes: - crop_hints (Sequence[google.cloud.vision_v1.types.CropHint]): - Crop hint results. - """ - - crop_hints = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='CropHint', - ) - - -class CropHintsParams(proto.Message): - r"""Parameters for crop hints annotation request. - - Attributes: - aspect_ratios (Sequence[float]): - Aspect ratios in floats, representing the - ratio of the width to the height of the image. - For example, if the desired aspect ratio is 4/3, - the corresponding float value should be 1.33333. - If not specified, the best possible crop is - returned. The number of provided aspect ratios - is limited to a maximum of 16; any aspect ratios - provided after the 16th are ignored. - """ - - aspect_ratios = proto.RepeatedField( - proto.FLOAT, - number=1, - ) - - -class WebDetectionParams(proto.Message): - r"""Parameters for web detection request. - - Attributes: - include_geo_results (bool): - Whether to include results derived from the - geo information in the image. - """ - - include_geo_results = proto.Field( - proto.BOOL, - number=2, - ) - - -class TextDetectionParams(proto.Message): - r"""Parameters for text detections. This is used to control - TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. - - Attributes: - enable_text_detection_confidence_score (bool): - By default, Cloud Vision API only includes confidence score - for DOCUMENT_TEXT_DETECTION result. Set the flag to true to - include confidence score for TEXT_DETECTION as well. - """ - - enable_text_detection_confidence_score = proto.Field( - proto.BOOL, - number=9, - ) - - -class ImageContext(proto.Message): - r"""Image context and/or feature-specific parameters. - - Attributes: - lat_long_rect (google.cloud.vision_v1.types.LatLongRect): - Not used. - language_hints (Sequence[str]): - List of languages to use for TEXT_DETECTION. 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). - Text detection returns an error if one or more of the - specified languages is not one of the `supported - languages `__. - crop_hints_params (google.cloud.vision_v1.types.CropHintsParams): - Parameters for crop hints annotation request. - product_search_params (google.cloud.vision_v1.types.ProductSearchParams): - Parameters for product search. - web_detection_params (google.cloud.vision_v1.types.WebDetectionParams): - Parameters for web detection. - text_detection_params (google.cloud.vision_v1.types.TextDetectionParams): - Parameters for text detection and document - text detection. - """ - - lat_long_rect = proto.Field( - proto.MESSAGE, - number=1, - message='LatLongRect', - ) - language_hints = proto.RepeatedField( - proto.STRING, - number=2, - ) - crop_hints_params = proto.Field( - proto.MESSAGE, - number=4, - message='CropHintsParams', - ) - product_search_params = proto.Field( - proto.MESSAGE, - number=5, - message=product_search.ProductSearchParams, - ) - web_detection_params = proto.Field( - proto.MESSAGE, - number=6, - message='WebDetectionParams', - ) - text_detection_params = proto.Field( - proto.MESSAGE, - number=12, - message='TextDetectionParams', - ) - - -class AnnotateImageRequest(proto.Message): - r"""Request for performing Google Cloud Vision API tasks over a - user-provided image, with user-requested features, and with - context information. - - Attributes: - image (google.cloud.vision_v1.types.Image): - The image to be processed. - features (Sequence[google.cloud.vision_v1.types.Feature]): - Requested features. - image_context (google.cloud.vision_v1.types.ImageContext): - Additional context that may accompany the - image. - """ - - image = proto.Field( - proto.MESSAGE, - number=1, - message='Image', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - - -class ImageAnnotationContext(proto.Message): - r"""If an image was produced from a file (e.g. a PDF), this - message gives information about the source of that image. - - Attributes: - uri (str): - The URI of the file used to produce the - image. - page_number (int): - If the file was a PDF or TIFF, this field - gives the page number within the file used to - produce the image. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - page_number = proto.Field( - proto.INT32, - number=2, - ) - - -class AnnotateImageResponse(proto.Message): - r"""Response to an image annotation request. - - Attributes: - face_annotations (Sequence[google.cloud.vision_v1.types.FaceAnnotation]): - If present, face detection has completed - successfully. - landmark_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): - If present, landmark detection has completed - successfully. - logo_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): - If present, logo detection has completed - successfully. - label_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): - If present, label detection has completed - successfully. - localized_object_annotations (Sequence[google.cloud.vision_v1.types.LocalizedObjectAnnotation]): - If present, localized object detection has - completed successfully. This will be sorted - descending by confidence score. - text_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]): - If present, text (OCR) detection has - completed successfully. - full_text_annotation (google.cloud.vision_v1.types.TextAnnotation): - If present, text (OCR) detection or document - (OCR) text detection has completed successfully. - This annotation provides the structural - hierarchy for the OCR detected text. - safe_search_annotation (google.cloud.vision_v1.types.SafeSearchAnnotation): - If present, safe-search annotation has - completed successfully. - image_properties_annotation (google.cloud.vision_v1.types.ImageProperties): - If present, image properties were extracted - successfully. - crop_hints_annotation (google.cloud.vision_v1.types.CropHintsAnnotation): - If present, crop hints have completed - successfully. - web_detection (google.cloud.vision_v1.types.WebDetection): - If present, web detection has completed - successfully. - product_search_results (google.cloud.vision_v1.types.ProductSearchResults): - If present, product search has completed - successfully. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the operation. Note - that filled-in image annotations are guaranteed to be - correct, even when ``error`` is set. - context (google.cloud.vision_v1.types.ImageAnnotationContext): - If present, contextual information is needed - to understand where this image comes from. - """ - - face_annotations = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='FaceAnnotation', - ) - landmark_annotations = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='EntityAnnotation', - ) - logo_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='EntityAnnotation', - ) - label_annotations = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='EntityAnnotation', - ) - localized_object_annotations = proto.RepeatedField( - proto.MESSAGE, - number=22, - message='LocalizedObjectAnnotation', - ) - text_annotations = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='EntityAnnotation', - ) - full_text_annotation = proto.Field( - proto.MESSAGE, - number=12, - message=text_annotation.TextAnnotation, - ) - safe_search_annotation = proto.Field( - proto.MESSAGE, - number=6, - message='SafeSearchAnnotation', - ) - image_properties_annotation = proto.Field( - proto.MESSAGE, - number=8, - message='ImageProperties', - ) - crop_hints_annotation = proto.Field( - proto.MESSAGE, - number=11, - message='CropHintsAnnotation', - ) - web_detection = proto.Field( - proto.MESSAGE, - number=13, - message=gcv_web_detection.WebDetection, - ) - product_search_results = proto.Field( - proto.MESSAGE, - number=14, - message=product_search.ProductSearchResults, - ) - error = proto.Field( - proto.MESSAGE, - number=9, - message=status_pb2.Status, - ) - context = proto.Field( - proto.MESSAGE, - number=21, - message='ImageAnnotationContext', - ) - - -class BatchAnnotateImagesRequest(proto.Message): - r"""Multiple image annotation requests are batched into a single - service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - parent (str): - Optional. Target project and location to make a call. - - Format: ``projects/{project-id}/locations/{location-id}``. - - If no parent is specified, a region will be chosen - automatically. - - Supported location-ids: ``us``: USA country only, ``asia``: - East asia areas, like Japan, Taiwan, ``eu``: The European - Union. - - Example: ``projects/project-A/locations/eu``. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - parent = proto.Field( - proto.STRING, - number=4, - ) - - -class BatchAnnotateImagesResponse(proto.Message): - r"""Response to a batch image annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): - Individual responses to image annotation - requests within the batch. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageResponse', - ) - - -class AnnotateFileRequest(proto.Message): - r"""A request to annotate one single file, e.g. a PDF, TIFF or - GIF file. - - Attributes: - input_config (google.cloud.vision_v1.types.InputConfig): - Required. Information about the input file. - features (Sequence[google.cloud.vision_v1.types.Feature]): - Required. Requested features. - image_context (google.cloud.vision_v1.types.ImageContext): - Additional context that may accompany the - image(s) in the file. - pages (Sequence[int]): - Pages of the file to perform image - annotation. - Pages starts from 1, we assume the first page of - the file is page 1. At most 5 pages are - supported per request. Pages can be negative. - Page 1 means the first page. - Page 2 means the second page. - Page -1 means the last page. - Page -2 means the second to the last page. - - If the file is GIF instead of PDF or TIFF, page - refers to GIF frames. - If this field is empty, by default the service - performs image annotation for the first 5 pages - of the file. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - pages = proto.RepeatedField( - proto.INT32, - number=4, - ) - - -class AnnotateFileResponse(proto.Message): - r"""Response to a single file annotation request. A file may - contain one or more images, which individually have their own - responses. - - Attributes: - input_config (google.cloud.vision_v1.types.InputConfig): - Information about the file for which this - response is generated. - responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]): - Individual responses to images found within the file. This - field will be empty if the ``error`` field is set. - total_pages (int): - This field gives the total number of pages in - the file. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the failed request. - The ``responses`` field will not be set in this case. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - responses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AnnotateImageResponse', - ) - total_pages = proto.Field( - proto.INT32, - number=3, - ) - error = proto.Field( - proto.MESSAGE, - number=4, - message=status_pb2.Status, - ) - - -class BatchAnnotateFilesRequest(proto.Message): - r"""A list of requests to annotate files using the - BatchAnnotateFiles API. - - Attributes: - requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]): - Required. The list of file annotation - requests. Right now we support only one - AnnotateFileRequest in - BatchAnnotateFilesRequest. - parent (str): - Optional. Target project and location to make a call. - - Format: ``projects/{project-id}/locations/{location-id}``. - - If no parent is specified, a region will be chosen - automatically. - - Supported location-ids: ``us``: USA country only, ``asia``: - East asia areas, like Japan, Taiwan, ``eu``: The European - Union. - - Example: ``projects/project-A/locations/eu``. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateFileRequest', - ) - parent = proto.Field( - proto.STRING, - number=3, - ) - - -class BatchAnnotateFilesResponse(proto.Message): - r"""A list of file annotation responses. - - Attributes: - responses (Sequence[google.cloud.vision_v1.types.AnnotateFileResponse]): - The list of file annotation responses, each - response corresponding to each - AnnotateFileRequest in - BatchAnnotateFilesRequest. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateFileResponse', - ) - - -class AsyncAnnotateFileRequest(proto.Message): - r"""An offline file annotation request. - - Attributes: - input_config (google.cloud.vision_v1.types.InputConfig): - Required. Information about the input file. - features (Sequence[google.cloud.vision_v1.types.Feature]): - Required. Requested features. - image_context (google.cloud.vision_v1.types.ImageContext): - Additional context that may accompany the - image(s) in the file. - output_config (google.cloud.vision_v1.types.OutputConfig): - Required. The desired output location and - metadata (e.g. format). - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - output_config = proto.Field( - proto.MESSAGE, - number=4, - message='OutputConfig', - ) - - -class AsyncAnnotateFileResponse(proto.Message): - r"""The response for a single offline file annotation request. - - Attributes: - output_config (google.cloud.vision_v1.types.OutputConfig): - The output location and metadata from - AsyncAnnotateFileRequest. - """ - - output_config = proto.Field( - proto.MESSAGE, - number=1, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateImagesRequest(proto.Message): - r"""Request for async image annotation for a list of images. - - Attributes: - requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - output_config (google.cloud.vision_v1.types.OutputConfig): - Required. The desired output location and - metadata (e.g. format). - parent (str): - Optional. Target project and location to make a call. - - Format: ``projects/{project-id}/locations/{location-id}``. - - If no parent is specified, a region will be chosen - automatically. - - Supported location-ids: ``us``: USA country only, ``asia``: - East asia areas, like Japan, Taiwan, ``eu``: The European - Union. - - Example: ``projects/project-A/locations/eu``. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - output_config = proto.Field( - proto.MESSAGE, - number=2, - message='OutputConfig', - ) - parent = proto.Field( - proto.STRING, - number=4, - ) - - -class AsyncBatchAnnotateImagesResponse(proto.Message): - r"""Response to an async batch image annotation request. - - Attributes: - output_config (google.cloud.vision_v1.types.OutputConfig): - The output location and metadata from - AsyncBatchAnnotateImagesRequest. - """ - - output_config = proto.Field( - proto.MESSAGE, - number=1, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateFilesRequest(proto.Message): - r"""Multiple async file annotation requests are batched into a - single service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]): - Required. Individual async file annotation - requests for this batch. - parent (str): - Optional. Target project and location to make a call. - - Format: ``projects/{project-id}/locations/{location-id}``. - - If no parent is specified, a region will be chosen - automatically. - - Supported location-ids: ``us``: USA country only, ``asia``: - East asia areas, like Japan, Taiwan, ``eu``: The European - Union. - - Example: ``projects/project-A/locations/eu``. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileRequest', - ) - parent = proto.Field( - proto.STRING, - number=4, - ) - - -class AsyncBatchAnnotateFilesResponse(proto.Message): - r"""Response to an async batch file annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1.types.AsyncAnnotateFileResponse]): - The list of file annotation responses, one - for each request in - AsyncBatchAnnotateFilesRequest. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileResponse', - ) - - -class InputConfig(proto.Message): - r"""The desired input location and metadata. - - Attributes: - gcs_source (google.cloud.vision_v1.types.GcsSource): - The Google Cloud Storage location to read the - input from. - content (bytes): - File content, represented as a stream of bytes. Note: As - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - - Currently, this field only works for BatchAnnotateFiles - requests. It does not work for AsyncBatchAnnotateFiles - requests. - mime_type (str): - The type of the file. Currently only - "application/pdf", "image/tiff" and "image/gif" - are supported. Wildcards are not supported. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - message='GcsSource', - ) - content = proto.Field( - proto.BYTES, - number=3, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class OutputConfig(proto.Message): - r"""The desired output location and metadata. - - Attributes: - gcs_destination (google.cloud.vision_v1.types.GcsDestination): - The Google Cloud Storage location to write - the output(s) to. - batch_size (int): - The max number of response protos to put into each output - JSON file 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 response - protos will be generated. If ``batch_size`` = 20, then 5 - json files each containing 20 response protos will be - written under the prefix ``gcs_destination``.\ ``uri``. - - Currently, batch_size only applies to GcsDestination, with - potential future support for other output configurations. - """ - - gcs_destination = proto.Field( - proto.MESSAGE, - number=1, - message='GcsDestination', - ) - batch_size = proto.Field( - proto.INT32, - number=2, - ) - - -class GcsSource(proto.Message): - r"""The Google Cloud Storage location where the input will be - read from. - - Attributes: - uri (str): - Google Cloud Storage URI for the input file. - This must only be a Google Cloud Storage object. - Wildcards are not currently supported. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class GcsDestination(proto.Message): - r"""The Google Cloud Storage location where the output will be - written to. - - Attributes: - uri (str): - Google Cloud Storage URI prefix where the results will be - stored. Results will be in JSON format and preceded by its - corresponding input URI prefix. This field can either - represent a gcs file prefix or gcs directory. In either - case, the uri should be unique because in order to get all - of the output files, you will need to do a wildcard gcs - search on the uri prefix you provide. - - Examples: - - - File Prefix: gs://bucket-name/here/filenameprefix The - output files will be created in gs://bucket-name/here/ - and the names of the output files will begin with - "filenameprefix". - - - Directory Prefix: gs://bucket-name/some/location/ The - output files will be created in - gs://bucket-name/some/location/ and the names of the - output files could be anything because there was no - filename prefix specified. - - If multiple outputs, each response is still - AnnotateFileResponse, each of which contains some subset of - the full list of AnnotateImageResponse. Multiple outputs can - happen if, for example, the output JSON is too large and - overflows into multiple sharded files. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class OperationMetadata(proto.Message): - r"""Contains metadata for the BatchAnnotateImages operation. - - Attributes: - state (google.cloud.vision_v1.types.OperationMetadata.State): - Current state of the batch operation. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was received. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the operation result was last - updated. - """ - class State(proto.Enum): - r"""Batch operation states.""" - STATE_UNSPECIFIED = 0 - CREATED = 1 - RUNNING = 2 - DONE = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - create_time = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=6, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py deleted file mode 100644 index 94fb4c70..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search.py +++ /dev/null @@ -1,222 +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.vision_v1.types import geometry -from google.cloud.vision_v1.types import product_search_service -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1', - manifest={ - 'ProductSearchParams', - 'ProductSearchResults', - }, -) - - -class ProductSearchParams(proto.Message): - r"""Parameters for a product search request. - - Attributes: - bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - The bounding polygon around the area of - interest in the image. If it is not specified, - system discretion will be applied. - product_set (str): - The resource name of a - [ProductSet][google.cloud.vision.v1.ProductSet] to be - searched for similar images. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. - product_categories (Sequence[str]): - The list of product categories to search in. - Currently, we only consider the first category, - and either "homegoods-v2", "apparel-v2", - "toys-v2", "packagedgoods-v1", or "general-v1" - should be specified. The legacy categories - "homegoods", "apparel", and "toys" are still - supported but will be deprecated. For new - products, please use "homegoods-v2", - "apparel-v2", or "toys-v2" for better product - search accuracy. It is recommended to migrate - existing products to these categories as well. - filter (str): - The filtering expression. This can be used to - restrict search results based on Product labels. - We currently support an AND of OR of key-value - expressions, where each expression within an OR - must have the same key. An '=' should be used to - connect the key and value. - For example, "(color = red OR color = blue) AND - brand = Google" is acceptable, but "(color = red - OR brand = Google)" is not acceptable. "color: - red" is not acceptable because it uses a ':' - instead of an '='. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=9, - message=geometry.BoundingPoly, - ) - product_set = proto.Field( - proto.STRING, - number=6, - ) - product_categories = proto.RepeatedField( - proto.STRING, - number=7, - ) - filter = proto.Field( - proto.STRING, - number=8, - ) - - -class ProductSearchResults(proto.Message): - r"""Results for a product search request. - - Attributes: - index_time (google.protobuf.timestamp_pb2.Timestamp): - Timestamp of the index which provided these - results. Products added to the product set and - products removed from the product set after this - time are not reflected in the current results. - results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.Result]): - List of results, one for each product match. - product_grouped_results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.GroupedResult]): - List of results grouped by products detected - in the query image. Each entry corresponds to - one bounding polygon in the query image, and - contains the matching products specific to that - region. There may be duplicate product matches - in the union of all the per-product results. - """ - - class Result(proto.Message): - r"""Information about a product. - - Attributes: - product (google.cloud.vision_v1.types.Product): - The Product. - score (float): - A confidence level on the match, ranging from - 0 (no confidence) to 1 (full confidence). - image (str): - The resource name of the image from the - product that is the closest match to the query. - """ - - product = proto.Field( - proto.MESSAGE, - number=1, - message=product_search_service.Product, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - image = proto.Field( - proto.STRING, - number=3, - ) - - class ObjectAnnotation(proto.Message): - r"""Prediction for what the object in the bounding box is. - - Attributes: - mid (str): - Object ID that should align with - EntityAnnotation mid. - 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. - name (str): - Object name, expressed in its ``language_code`` language. - score (float): - Score of the result. Range [0, 1]. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - name = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - - class GroupedResult(proto.Message): - r"""Information about the products similar to a single product in - a query image. - - Attributes: - bounding_poly (google.cloud.vision_v1.types.BoundingPoly): - The bounding polygon around the product - detected in the query image. - results (Sequence[google.cloud.vision_v1.types.ProductSearchResults.Result]): - List of results, one for each product match. - object_annotations (Sequence[google.cloud.vision_v1.types.ProductSearchResults.ObjectAnnotation]): - List of generic predictions for the object in - the bounding box. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - results = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='ProductSearchResults.Result', - ) - object_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='ProductSearchResults.ObjectAnnotation', - ) - - index_time = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - results = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=Result, - ) - product_grouped_results = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=GroupedResult, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py deleted file mode 100644 index a7f76aa0..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/product_search_service.py +++ /dev/null @@ -1,1075 +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.vision_v1.types import geometry -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1', - manifest={ - 'Product', - 'ProductSet', - 'ReferenceImage', - 'CreateProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'GetProductRequest', - 'UpdateProductRequest', - 'DeleteProductRequest', - 'CreateProductSetRequest', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'GetProductSetRequest', - 'UpdateProductSetRequest', - 'DeleteProductSetRequest', - 'CreateReferenceImageRequest', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'GetReferenceImageRequest', - 'DeleteReferenceImageRequest', - 'AddProductToProductSetRequest', - 'RemoveProductFromProductSetRequest', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'BatchOperationMetadata', - 'ProductSetPurgeConfig', - 'PurgeProductsRequest', - }, -) - - -class Product(proto.Message): - r"""A Product contains ReferenceImages. - - Attributes: - name (str): - The resource name of the product. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This field is ignored when creating a product. - display_name (str): - The user-provided name for this Product. Must - not be empty. Must be at most 4096 characters - long. - description (str): - User-provided metadata to be stored with this - product. Must be at most 4096 characters long. - product_category (str): - Immutable. The category for the product - identified by the reference image. This should - be one of "homegoods-v2", "apparel-v2", - "toys-v2", "packagedgoods-v1" or "general-v1". - The legacy categories "homegoods", "apparel", - and "toys" are still supported, but these should - not be used for new products. - product_labels (Sequence[google.cloud.vision_v1.types.Product.KeyValue]): - Key-value pairs that can be attached to a product. At query - time, constraints can be specified based on the - product_labels. - - Note that integer values can be provided as strings, e.g. - "1199". Only strings with integer values can match a - range-based restriction which is to be supported soon. - - Multiple values can be assigned to the same key. One product - may have up to 500 product_labels. - - Notice that the total number of distinct product_labels over - all products in one ProductSet cannot exceed 1M, otherwise - the product search pipeline will refuse to work for that - ProductSet. - """ - - class KeyValue(proto.Message): - r"""A product label represented as a key-value pair. - - Attributes: - key (str): - The key of the label attached to the product. - Cannot be empty and cannot exceed 128 bytes. - value (str): - The value of the label attached to the - product. Cannot be empty and cannot exceed 128 - bytes. - """ - - key = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - product_category = proto.Field( - proto.STRING, - number=4, - ) - product_labels = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=KeyValue, - ) - - -class ProductSet(proto.Message): - r"""A ProductSet contains Products. A ProductSet can contain a - maximum of 1 million reference images. If the limit is exceeded, - periodic indexing will fail. - - Attributes: - name (str): - The resource name of the ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. - - This field is ignored when creating a ProductSet. - display_name (str): - The user-provided name for this ProductSet. - Must not be empty. Must be at most 4096 - characters long. - index_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which this - ProductSet was last indexed. Query results will - reflect all updates before this time. If this - ProductSet has never been indexed, this - timestamp is the default value - "1970-01-01T00:00:00Z". - - This field is ignored when creating a - ProductSet. - index_error (google.rpc.status_pb2.Status): - Output only. If there was an error with - indexing the product set, the field is - populated. - This field is ignored when creating a - ProductSet. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - index_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - index_error = proto.Field( - proto.MESSAGE, - number=4, - message=status_pb2.Status, - ) - - -class ReferenceImage(proto.Message): - r"""A ``ReferenceImage`` represents a product image and its associated - metadata, such as bounding boxes. - - Attributes: - name (str): - The resource name of the reference image. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - This field is ignored when creating a reference image. - uri (str): - Required. The Google Cloud Storage URI of the reference - image. - - The URI must start with ``gs://``. - bounding_polys (Sequence[google.cloud.vision_v1.types.BoundingPoly]): - Optional. Bounding polygons around the areas - of interest in the reference image. If this - field is empty, the system will try to detect - regions of interest. At most 10 bounding - polygons will be used. - The provided shape is converted into a non- - rotated rectangle. Once converted, the small - edge of the rectangle must be greater than or - equal to 300 pixels. The aspect ratio must be - 1:4 or less (i.e. 1:3 is ok; 1:5 is not). - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - uri = proto.Field( - proto.STRING, - number=2, - ) - bounding_polys = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=geometry.BoundingPoly, - ) - - -class CreateProductRequest(proto.Message): - r"""Request message for the ``CreateProduct`` method. - - Attributes: - parent (str): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product (google.cloud.vision_v1.types.Product): - Required. The product to create. - product_id (str): - A user-supplied resource id for this Product. If set, the - server will attempt to use this value as the resource id. If - it is already in use, an error is returned with code - ALREADY_EXISTS. Must be at most 128 characters long. It - cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.MESSAGE, - number=2, - message='Product', - ) - product_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsRequest(proto.Message): - r"""Request message for the ``ListProducts`` method. - - Attributes: - parent (str): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsResponse(proto.Message): - r"""Response message for the ``ListProducts`` method. - - Attributes: - products (Sequence[google.cloud.vision_v1.types.Product]): - List of products. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - products = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class GetProductRequest(proto.Message): - r"""Request message for the ``GetProduct`` method. - - Attributes: - name (str): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateProductRequest(proto.Message): - r"""Request message for the ``UpdateProduct`` method. - - Attributes: - product (google.cloud.vision_v1.types.Product): - Required. The Product resource which replaces - the one on the server. product.name is - immutable. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that specifies - which fields to update. If update_mask isn't specified, all - mutable fields are to be updated. Valid mask paths include - ``product_labels``, ``display_name``, and ``description``. - """ - - product = proto.Field( - proto.MESSAGE, - number=1, - message='Product', - ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteProductRequest(proto.Message): - r"""Request message for the ``DeleteProduct`` method. - - Attributes: - name (str): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateProductSetRequest(proto.Message): - r"""Request message for the ``CreateProductSet`` method. - - Attributes: - parent (str): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product_set (google.cloud.vision_v1.types.ProductSet): - Required. The ProductSet to create. - product_set_id (str): - A user-supplied resource id for this ProductSet. If set, the - server will attempt to use this value as the resource id. If - it is already in use, an error is returned with code - ALREADY_EXISTS. Must be at most 128 characters long. It - cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - product_set = proto.Field( - proto.MESSAGE, - number=2, - message='ProductSet', - ) - product_set_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductSetsRequest(proto.Message): - r"""Request message for the ``ListProductSets`` method. - - Attributes: - parent (str): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductSetsResponse(proto.Message): - r"""Response message for the ``ListProductSets`` method. - - Attributes: - product_sets (Sequence[google.cloud.vision_v1.types.ProductSet]): - List of ProductSets. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - product_sets = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ProductSet', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class GetProductSetRequest(proto.Message): - r"""Request message for the ``GetProductSet`` method. - - Attributes: - name (str): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateProductSetRequest(proto.Message): - r"""Request message for the ``UpdateProductSet`` method. - - Attributes: - product_set (google.cloud.vision_v1.types.ProductSet): - Required. The ProductSet resource which - replaces the one on the server. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that specifies - which fields to update. If update_mask isn't specified, all - mutable fields are to be updated. Valid mask path is - ``display_name``. - """ - - product_set = proto.Field( - proto.MESSAGE, - number=1, - message='ProductSet', - ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteProductSetRequest(proto.Message): - r"""Request message for the ``DeleteProductSet`` method. - - Attributes: - name (str): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateReferenceImageRequest(proto.Message): - r"""Request message for the ``CreateReferenceImage`` method. - - Attributes: - parent (str): - Required. Resource name of the product in which to create - the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - reference_image (google.cloud.vision_v1.types.ReferenceImage): - Required. The reference image to create. - If an image ID is specified, it is ignored. - reference_image_id (str): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value as - the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - reference_image = proto.Field( - proto.MESSAGE, - number=2, - message='ReferenceImage', - ) - reference_image_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListReferenceImagesRequest(proto.Message): - r"""Request message for the ``ListReferenceImages`` method. - - Attributes: - parent (str): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - A token identifying a page of results to be returned. This - is the value of ``nextPageToken`` returned in a previous - reference image list request. - - Defaults to the first page if not specified. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListReferenceImagesResponse(proto.Message): - r"""Response message for the ``ListReferenceImages`` method. - - Attributes: - reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): - The list of reference images. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - next_page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - @property - def raw_page(self): - return self - - reference_images = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ReferenceImage', - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - next_page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class GetReferenceImageRequest(proto.Message): - r"""Request message for the ``GetReferenceImage`` method. - - Attributes: - name (str): - Required. The resource name of the ReferenceImage to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class DeleteReferenceImageRequest(proto.Message): - r"""Request message for the ``DeleteReferenceImage`` method. - - Attributes: - name (str): - Required. The resource name of the reference image to - delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class AddProductToProductSetRequest(proto.Message): - r"""Request message for the ``AddProductToProductSet`` method. - - Attributes: - name (str): - Required. The resource name for the ProductSet to modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - product (str): - Required. The resource name for the Product to be added to - this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.STRING, - number=2, - ) - - -class RemoveProductFromProductSetRequest(proto.Message): - r"""Request message for the ``RemoveProductFromProductSet`` method. - - Attributes: - name (str): - Required. The resource name for the ProductSet to modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - product (str): - Required. The resource name for the Product to be removed - from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.STRING, - number=2, - ) - - -class ListProductsInProductSetRequest(proto.Message): - r"""Request message for the ``ListProductsInProductSet`` method. - - Attributes: - name (str): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsInProductSetResponse(proto.Message): - r"""Response message for the ``ListProductsInProductSet`` method. - - Attributes: - products (Sequence[google.cloud.vision_v1.types.Product]): - The list of Products. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - products = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class ImportProductSetsGcsSource(proto.Message): - r"""The Google Cloud Storage location for a csv file which - preserves a list of ImportProductSetRequests in each line. - - Attributes: - csv_file_uri (str): - The Google Cloud Storage URI of the input csv file. - - The URI must start with ``gs://``. - - The format of the input csv file should be one image per - line. In each line, there are 8 columns. - - 1. image-uri - 2. image-id - 3. product-set-id - 4. product-id - 5. product-category - 6. product-display-name - 7. labels - 8. bounding-poly - - The ``image-uri``, ``product-set-id``, ``product-id``, and - ``product-category`` columns are required. All other columns - are optional. - - If the ``ProductSet`` or ``Product`` specified by the - ``product-set-id`` and ``product-id`` values does not exist, - then the system will create a new ``ProductSet`` or - ``Product`` for the image. In this case, the - ``product-display-name`` column refers to - [display_name][google.cloud.vision.v1.Product.display_name], - the ``product-category`` column refers to - [product_category][google.cloud.vision.v1.Product.product_category], - and the ``labels`` column refers to - [product_labels][google.cloud.vision.v1.Product.product_labels]. - - The ``image-id`` column is optional but must be unique if - provided. If it is empty, the system will automatically - assign a unique id to the image. - - The ``product-display-name`` column is optional. If it is - empty, the system sets the - [display_name][google.cloud.vision.v1.Product.display_name] - field for the product to a space (" "). You can update the - ``display_name`` later by using the API. - - If a ``Product`` with the specified ``product-id`` already - exists, then the system ignores the - ``product-display-name``, ``product-category``, and - ``labels`` columns. - - The ``labels`` column (optional) is a line containing a list - of comma-separated key-value pairs, in the following format: - - :: - - "key_1=value_1,key_2=value_2,...,key_n=value_n" - - The ``bounding-poly`` column (optional) identifies one - region of interest from the image in the same manner as - ``CreateReferenceImage``. If you do not specify the - ``bounding-poly`` column, then the system will try to detect - regions of interest automatically. - - At most one ``bounding-poly`` column is allowed per line. If - the image contains multiple regions of interest, add a line - to the CSV file that includes the same product information, - and the ``bounding-poly`` values for each region of - interest. - - The ``bounding-poly`` column must contain an even number of - comma-separated numbers, in the format - "p1_x,p1_y,p2_x,p2_y,...,pn_x,pn_y". Use non-negative - integers for absolute bounding polygons, and float values in - [0, 1] for normalized bounding polygons. - - The system will resize the image if the image resolution is - too large to process (larger than 20MP). - """ - - csv_file_uri = proto.Field( - proto.STRING, - number=1, - ) - - -class ImportProductSetsInputConfig(proto.Message): - r"""The input content for the ``ImportProductSets`` method. - - Attributes: - gcs_source (google.cloud.vision_v1.types.ImportProductSetsGcsSource): - The Google Cloud Storage location for a csv - file which preserves a list of - ImportProductSetRequests in each line. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - oneof='source', - message='ImportProductSetsGcsSource', - ) - - -class ImportProductSetsRequest(proto.Message): - r"""Request message for the ``ImportProductSets`` method. - - Attributes: - parent (str): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - input_config (google.cloud.vision_v1.types.ImportProductSetsInputConfig): - Required. The input content for the list of - requests. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - input_config = proto.Field( - proto.MESSAGE, - number=2, - message='ImportProductSetsInputConfig', - ) - - -class ImportProductSetsResponse(proto.Message): - r"""Response message for the ``ImportProductSets`` method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - Attributes: - reference_images (Sequence[google.cloud.vision_v1.types.ReferenceImage]): - The list of reference_images that are imported successfully. - statuses (Sequence[google.rpc.status_pb2.Status]): - The rpc status for each ImportProductSet request, including - both successes and errors. - - The number of statuses here matches the number of lines in - the csv file, and statuses[i] stores the success or failure - status of processing the i-th line of the csv, starting from - line 0. - """ - - reference_images = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ReferenceImage', - ) - statuses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=status_pb2.Status, - ) - - -class BatchOperationMetadata(proto.Message): - r"""Metadata for the batch operations such as the current state. - - This is included in the ``metadata`` field of the ``Operation`` - returned by the ``GetOperation`` call of the - ``google::longrunning::Operations`` service. - - Attributes: - state (google.cloud.vision_v1.types.BatchOperationMetadata.State): - The current state of the batch operation. - submit_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was submitted - to the server. - end_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request is finished and - [google.longrunning.Operation.done][google.longrunning.Operation.done] - is set to true. - """ - class State(proto.Enum): - r"""Enumerates the possible states that the batch request can be - in. - """ - STATE_UNSPECIFIED = 0 - PROCESSING = 1 - SUCCESSFUL = 2 - FAILED = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - submit_time = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - end_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -class ProductSetPurgeConfig(proto.Message): - r"""Config to control which ProductSet contains the Products to - be deleted. - - Attributes: - product_set_id (str): - The ProductSet that contains the Products to delete. If a - Product is a member of product_set_id in addition to other - ProductSets, the Product will still be deleted. - """ - - product_set_id = proto.Field( - proto.STRING, - number=1, - ) - - -class PurgeProductsRequest(proto.Message): - r"""Request message for the ``PurgeProducts`` method. - - Attributes: - product_set_purge_config (google.cloud.vision_v1.types.ProductSetPurgeConfig): - Specify which ProductSet contains the - Products to be deleted. - delete_orphan_products (bool): - If delete_orphan_products is true, all Products that are not - in any ProductSet will be deleted. - parent (str): - Required. The project and location in which the Products - should be deleted. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - force (bool): - The default value is false. Override this - value to true to actually perform the purge. - """ - - product_set_purge_config = proto.Field( - proto.MESSAGE, - number=2, - oneof='target', - message='ProductSetPurgeConfig', - ) - delete_orphan_products = proto.Field( - proto.BOOL, - number=3, - oneof='target', - ) - parent = proto.Field( - proto.STRING, - number=1, - ) - force = proto.Field( - proto.BOOL, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py deleted file mode 100644 index 4b0d8b6e..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/text_annotation.py +++ /dev/null @@ -1,393 +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.vision_v1.types import geometry - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1', - manifest={ - 'TextAnnotation', - 'Page', - 'Block', - 'Paragraph', - 'Word', - 'Symbol', - }, -) - - -class TextAnnotation(proto.Message): - r"""TextAnnotation contains a structured representation of OCR extracted - text. The hierarchy of an OCR extracted text structure is like this: - TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each - structural component, starting from Page, may further have their own - properties. Properties describe detected languages, breaks etc.. - Please refer to the - [TextAnnotation.TextProperty][google.cloud.vision.v1.TextAnnotation.TextProperty] - message definition below for more detail. - - Attributes: - pages (Sequence[google.cloud.vision_v1.types.Page]): - List of pages detected by OCR. - text (str): - UTF-8 text detected on the pages. - """ - - 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, - ) - - class DetectedBreak(proto.Message): - r"""Detected start or end of a structural component. - - Attributes: - type_ (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak.BreakType): - Detected break type. - is_prefix (bool): - True if break prepends the element. - """ - class BreakType(proto.Enum): - r"""Enum to denote the type of break found. New line, space etc.""" - UNKNOWN = 0 - SPACE = 1 - SURE_SPACE = 2 - EOL_SURE_SPACE = 3 - HYPHEN = 4 - LINE_BREAK = 5 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='TextAnnotation.DetectedBreak.BreakType', - ) - is_prefix = proto.Field( - proto.BOOL, - number=2, - ) - - class TextProperty(proto.Message): - r"""Additional information detected on the structural component. - - Attributes: - detected_languages (Sequence[google.cloud.vision_v1.types.TextAnnotation.DetectedLanguage]): - A list of detected languages together with - confidence. - detected_break (google.cloud.vision_v1.types.TextAnnotation.DetectedBreak): - Detected start or end of a text segment. - """ - - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='TextAnnotation.DetectedLanguage', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='TextAnnotation.DetectedBreak', - ) - - pages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Page', - ) - text = proto.Field( - proto.STRING, - number=2, - ) - - -class Page(proto.Message): - r"""Detected page from OCR. - - Attributes: - property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): - Additional information detected on the page. - width (int): - Page width. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - height (int): - Page height. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - blocks (Sequence[google.cloud.vision_v1.types.Block]): - List of blocks of text, images etc on this - page. - confidence (float): - Confidence of the OCR results on the page. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - width = proto.Field( - proto.INT32, - number=2, - ) - height = proto.Field( - proto.INT32, - number=3, - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Block', - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Block(proto.Message): - r"""Logical element on the page. - - Attributes: - property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): - Additional information detected for the - block. - bounding_box (google.cloud.vision_v1.types.BoundingPoly): - The bounding box for the block. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: - - :: - - 0----1 - | | - 3----2 - - - when it's rotated 180 degrees around the top-left corner - it becomes: - - :: - - 2----3 - | | - 1----0 - - and the vertex order will still be (0, 1, 2, 3). - paragraphs (Sequence[google.cloud.vision_v1.types.Paragraph]): - List of paragraphs in this block (if this - blocks is of type text). - block_type (google.cloud.vision_v1.types.Block.BlockType): - Detected block type (text, image etc) for - this block. - confidence (float): - Confidence of the OCR results on the block. Range [0, 1]. - """ - class BlockType(proto.Enum): - r"""Type of a block (text, image etc) as identified by OCR.""" - UNKNOWN = 0 - TEXT = 1 - TABLE = 2 - PICTURE = 3 - RULER = 4 - BARCODE = 5 - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Paragraph', - ) - block_type = proto.Field( - proto.ENUM, - number=4, - enum=BlockType, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Paragraph(proto.Message): - r"""Structural unit of text representing a number of words in - certain order. - - Attributes: - property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): - Additional information detected for the - paragraph. - bounding_box (google.cloud.vision_v1.types.BoundingPoly): - The bounding box for the paragraph. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). - words (Sequence[google.cloud.vision_v1.types.Word]): - List of all words in this paragraph. - confidence (float): - Confidence of the OCR results for the paragraph. Range [0, - 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - words = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Word', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Word(proto.Message): - r"""A word representation. - - Attributes: - property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): - Additional information detected for the word. - bounding_box (google.cloud.vision_v1.types.BoundingPoly): - The bounding box for the word. The vertices are in the order - of top-left, top-right, bottom-right, bottom-left. When a - rotation of the bounding box is detected the rotation is - represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). - symbols (Sequence[google.cloud.vision_v1.types.Symbol]): - List of symbols in the word. - The order of the symbols follows the natural - reading order. - confidence (float): - Confidence of the OCR results for the word. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - symbols = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Symbol', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Symbol(proto.Message): - r"""A single symbol representation. - - Attributes: - property (google.cloud.vision_v1.types.TextAnnotation.TextProperty): - Additional information detected for the - symbol. - bounding_box (google.cloud.vision_v1.types.BoundingPoly): - The bounding box for the symbol. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). - text (str): - The actual UTF-8 representation of the - symbol. - confidence (float): - Confidence of the OCR results for the symbol. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - text = proto.Field( - proto.STRING, - number=3, - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.py b/owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.py deleted file mode 100644 index 1aa0be69..00000000 --- a/owl-bot-staging/v1/google/cloud/vision_v1/types/web_detection.py +++ /dev/null @@ -1,201 +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.vision.v1', - manifest={ - 'WebDetection', - }, -) - - -class WebDetection(proto.Message): - r"""Relevant information for the image from the Internet. - - Attributes: - web_entities (Sequence[google.cloud.vision_v1.types.WebDetection.WebEntity]): - Deduced entities from similar images on the - Internet. - full_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): - Fully matching images from the Internet. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): - Partial matching images from the Internet. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - pages_with_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebPage]): - Web pages containing the matching images from - the Internet. - visually_similar_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): - The visually similar image results. - best_guess_labels (Sequence[google.cloud.vision_v1.types.WebDetection.WebLabel]): - The service's best guess as to the topic of - the request image. Inferred from similar images - on the open web. - """ - - class WebEntity(proto.Message): - r"""Entity deduced from similar images on the Internet. - - Attributes: - entity_id (str): - Opaque entity ID. - score (float): - Overall relevancy score for the entity. - Not normalized and not comparable across - different image queries. - description (str): - Canonical description of the entity, in - English. - """ - - entity_id = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - - class WebImage(proto.Message): - r"""Metadata for online images. - - Attributes: - url (str): - The result image URL. - score (float): - (Deprecated) Overall relevancy score for the - image. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - - class WebPage(proto.Message): - r"""Metadata for web pages. - - Attributes: - url (str): - The result web page URL. - score (float): - (Deprecated) Overall relevancy score for the - web page. - page_title (str): - Title for the web page, may contain HTML - markups. - full_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): - Fully matching images on the page. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1.types.WebDetection.WebImage]): - Partial matching images on the page. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - page_title = proto.Field( - proto.STRING, - number=3, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='WebDetection.WebImage', - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='WebDetection.WebImage', - ) - - class WebLabel(proto.Message): - r"""Label to provide extra metadata for the web detection. - - Attributes: - label (str): - Label for extra metadata. - language_code (str): - The BCP-47 language code for ``label``, such as "en-US" or - "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - """ - - label = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - - web_entities = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=WebEntity, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=WebImage, - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=WebImage, - ) - pages_with_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=WebPage, - ) - visually_similar_images = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=WebImage, - ) - best_guess_labels = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=WebLabel, - ) - - -__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 18bc9985..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/vision_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_vision_v1_keywords.py b/owl-bot-staging/v1/scripts/fixup_vision_v1_keywords.py deleted file mode 100644 index a4842deb..00000000 --- a/owl-bot-staging/v1/scripts/fixup_vision_v1_keywords.py +++ /dev/null @@ -1,198 +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 visionCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'add_product_to_product_set': ('name', 'product', ), - 'async_batch_annotate_files': ('requests', 'parent', ), - 'async_batch_annotate_images': ('requests', 'output_config', 'parent', ), - 'batch_annotate_files': ('requests', 'parent', ), - 'batch_annotate_images': ('requests', 'parent', ), - 'create_product': ('parent', 'product', 'product_id', ), - 'create_product_set': ('parent', 'product_set', 'product_set_id', ), - 'create_reference_image': ('parent', 'reference_image', 'reference_image_id', ), - 'delete_product': ('name', ), - 'delete_product_set': ('name', ), - 'delete_reference_image': ('name', ), - 'get_product': ('name', ), - 'get_product_set': ('name', ), - 'get_reference_image': ('name', ), - 'import_product_sets': ('parent', 'input_config', ), - 'list_products': ('parent', 'page_size', 'page_token', ), - 'list_product_sets': ('parent', 'page_size', 'page_token', ), - 'list_products_in_product_set': ('name', 'page_size', 'page_token', ), - 'list_reference_images': ('parent', 'page_size', 'page_token', ), - 'purge_products': ('parent', 'product_set_purge_config', 'delete_orphan_products', 'force', ), - 'remove_product_from_product_set': ('name', 'product', ), - 'update_product': ('product', 'update_mask', ), - 'update_product_set': ('product_set', 'update_mask', ), - } - - 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: a.keyword.value not 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=visionCallTransformer(), -): - """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 vision 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 9d03e702..00000000 --- a/owl-bot-staging/v1/setup.py +++ /dev/null @@ -1,54 +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-vision', - 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, < 3.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', - 'Programming Language :: Python :: 3.9', - '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/vision_v1/__init__.py b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1/tests/unit/gapic/vision_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/vision_v1/test_image_annotator.py b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_image_annotator.py deleted file mode 100644 index f4c55cf2..00000000 --- a/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_image_annotator.py +++ /dev/null @@ -1,1723 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorAsyncClient -from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorClient -from google.cloud.vision_v1.services.image_annotator import transports -from google.cloud.vision_v1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1.types import geometry -from google.cloud.vision_v1.types import image_annotator -from google.cloud.vision_v1.types import product_search -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ImageAnnotatorGrpcTransport, "grpc"), - (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -def test_image_annotator_client_get_transport_class(): - transport = ImageAnnotatorClient.get_transport_class() - available_transports = [ - transports.ImageAnnotatorGrpcTransport, - ] - assert transport in available_transports - - transport = ImageAnnotatorClient.get_transport_class("grpc") - assert transport == transports.ImageAnnotatorGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - -def test_image_annotator_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ImageAnnotatorClient( - 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, - always_use_jwt_access=True, - ) - - -def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse( - ) - response = client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - -def test_batch_annotate_images_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 = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - client.batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( - )) - response = await client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async_from_dict(): - await test_batch_annotate_images_async(request_type=dict) - - -def test_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -def test_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -def test_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateFilesRequest): - client = ImageAnnotatorClient( - 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_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateFilesResponse( - ) - response = client.batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) - - -def test_batch_annotate_files_from_dict(): - test_batch_annotate_files(request_type=dict) - - -def test_batch_annotate_files_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 = ImageAnnotatorClient( - 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_annotate_files), - '__call__') as call: - client.batch_annotate_files() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateFilesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateFilesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse( - )) - response = await client.batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_files_async_from_dict(): - await test_batch_annotate_files_async(request_type=dict) - - -def test_batch_annotate_files_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateFilesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_files( - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -def test_batch_annotate_files_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_files( - image_annotator.BatchAnnotateFilesRequest(), - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_files_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateFilesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_files( - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -@pytest.mark.asyncio -async def test_batch_annotate_files_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_files( - image_annotator.BatchAnnotateFilesRequest(), - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -def test_async_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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.async_batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.async_batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_async_batch_annotate_images_from_dict(): - test_async_batch_annotate_images(request_type=dict) - - -def test_async_batch_annotate_images_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 = ImageAnnotatorClient( - 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.async_batch_annotate_images), - '__call__') as call: - client.async_batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_images), - '__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.async_batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_async_from_dict(): - await test_async_batch_annotate_images_async(request_type=dict) - - -def test_async_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_images), - '__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.async_batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) - - -def test_async_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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.async_batch_annotate_images( - image_annotator.AsyncBatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), - ) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_images), - '__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.async_batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_images( - image_annotator.AsyncBatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), - ) - - -def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - -def test_async_batch_annotate_files_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 = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - client.async_batch_annotate_files() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files), - '__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.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async_from_dict(): - await test_async_batch_annotate_files_async(request_type=dict) - - -def test_async_batch_annotate_files_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -def test_async_batch_annotate_files_flattened_error(): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ImageAnnotatorClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, -]) -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 = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ImageAnnotatorGrpcTransport, - ) - -def test_image_annotator_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_image_annotator_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'batch_annotate_images', - 'batch_annotate_files', - 'async_batch_annotate_images', - 'async_batch_annotate_files', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_image_annotator_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.vision_v1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ImageAnnotatorGrpcTransport, grpc_helpers), - (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_image_annotator_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_host_no_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_image_annotator_host_with_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_image_annotator_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcTransport( - 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_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_grpc_lro_client(): - client = ImageAnnotatorClient( - 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_image_annotator_grpc_lro_async_client(): - client = ImageAnnotatorAsyncClient( - 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_product_path(): - project = "squid" - location = "clam" - product = "whelk" - expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - actual = ImageAnnotatorClient.product_path(project, location, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "project": "octopus", - "location": "oyster", - "product": "nudibranch", - } - path = ImageAnnotatorClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_product_path(path) - assert expected == actual - -def test_product_set_path(): - project = "cuttlefish" - location = "mussel" - product_set = "winkle" - expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - actual = ImageAnnotatorClient.product_set_path(project, location, product_set) - assert expected == actual - - -def test_parse_product_set_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "product_set": "abalone", - } - path = ImageAnnotatorClient.product_set_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_product_set_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ImageAnnotatorClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ImageAnnotatorClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = ImageAnnotatorClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ImageAnnotatorClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ImageAnnotatorClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ImageAnnotatorClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = ImageAnnotatorClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ImageAnnotatorClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ImageAnnotatorClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - transport_class = ImageAnnotatorClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py b/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py deleted file mode 100644 index 3d3b6976..00000000 --- a/owl-bot-staging/v1/tests/unit/gapic/vision_v1/test_product_search.py +++ /dev/null @@ -1,6323 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1.services.product_search import ProductSearchAsyncClient -from google.cloud.vision_v1.services.product_search import ProductSearchClient -from google.cloud.vision_v1.services.product_search import pagers -from google.cloud.vision_v1.services.product_search import transports -from google.cloud.vision_v1.services.product_search.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1.types import geometry -from google.cloud.vision_v1.types import product_search_service -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -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 ProductSearchClient._get_default_mtls_endpoint(None) is None - assert ProductSearchClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ProductSearchClient, - ProductSearchAsyncClient, -]) -def test_product_search_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductSearchGrpcTransport, "grpc"), - (transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ProductSearchClient, - ProductSearchAsyncClient, -]) -def test_product_search_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 == 'vision.googleapis.com:443' - - -def test_product_search_client_get_transport_class(): - transport = ProductSearchClient.get_transport_class() - available_transports = [ - transports.ProductSearchGrpcTransport, - ] - assert transport in available_transports - - transport = ProductSearchClient.get_transport_class("grpc") - assert transport == transports.ProductSearchGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) -@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) -def test_product_search_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(ProductSearchClient, '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(ProductSearchClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "true"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "false"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) -@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_product_search_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_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, - always_use_jwt_access=True, - ) - - -def test_product_search_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1.services.product_search.transports.ProductSearchGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ProductSearchClient( - 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, - always_use_jwt_access=True, - ) - - -def test_create_product_set(transport: str = 'grpc', request_type=product_search_service.CreateProductSetRequest): - client = ProductSearchClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.create_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_create_product_set_from_dict(): - test_create_product_set(request_type=dict) - - -def test_create_product_set_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 = ProductSearchClient( - 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_product_set), - '__call__') as call: - client.create_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - -@pytest.mark.asyncio -async def test_create_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductSetRequest): - client = ProductSearchAsyncClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.create_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_create_product_set_async_from_dict(): - await test_create_product_set_async(request_type=dict) - - -def test_create_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateProductSetRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.create_product_set(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_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateProductSetRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.create_product_set(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_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_product_set( - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].product_set_id == 'product_set_id_value' - - -def test_create_product_set_flattened_error(): - client = ProductSearchClient( - 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_product_set( - product_search_service.CreateProductSetRequest(), - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_product_set( - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].product_set_id == 'product_set_id_value' - - -@pytest.mark.asyncio -async def test_create_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_set( - product_search_service.CreateProductSetRequest(), - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_value', - ) - - -def test_list_product_sets(transport: str = 'grpc', request_type=product_search_service.ListProductSetsRequest): - client = ProductSearchClient( - 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_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductSetsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_product_sets_from_dict(): - test_list_product_sets(request_type=dict) - - -def test_list_product_sets_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 = ProductSearchClient( - 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_product_sets), - '__call__') as call: - client.list_product_sets() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - -@pytest.mark.asyncio -async def test_list_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductSetsRequest): - client = ProductSearchAsyncClient( - 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_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductSetsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_product_sets_async_from_dict(): - await test_list_product_sets_async(request_type=dict) - - -def test_list_product_sets_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - call.return_value = product_search_service.ListProductSetsResponse() - client.list_product_sets(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_product_sets_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) - await client.list_product_sets(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_product_sets_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_product_sets( - 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_product_sets_flattened_error(): - client = ProductSearchClient( - 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_product_sets( - product_search_service.ListProductSetsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_product_sets_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_product_sets( - 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_product_sets_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_sets( - product_search_service.ListProductSetsRequest(), - parent='parent_value', - ) - - -def test_list_product_sets_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_product_sets(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.ProductSet) - for i in results) - -def test_list_product_sets_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - pages = list(client.list_product_sets(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_product_sets_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_product_sets(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, product_search_service.ProductSet) - for i in responses) - -@pytest.mark.asyncio -async def test_list_product_sets_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_product_sets(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_product_set(transport: str = 'grpc', request_type=product_search_service.GetProductSetRequest): - client = ProductSearchClient( - 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.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.get_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_get_product_set_from_dict(): - test_get_product_set(request_type=dict) - - -def test_get_product_set_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 = ProductSearchClient( - 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.get_product_set), - '__call__') as call: - client.get_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - -@pytest.mark.asyncio -async def test_get_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductSetRequest): - client = ProductSearchAsyncClient( - 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.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.get_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_get_product_set_async_from_dict(): - await test_get_product_set_async(request_type=dict) - - -def test_get_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.get_product_set(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_get_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.get_product_set(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_get_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product_set( - 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_get_product_set_flattened_error(): - client = ProductSearchClient( - 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.get_product_set( - product_search_service.GetProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product_set( - 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_get_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_product_set( - product_search_service.GetProductSetRequest(), - name='name_value', - ) - - -def test_update_product_set(transport: str = 'grpc', request_type=product_search_service.UpdateProductSetRequest): - client = ProductSearchClient( - 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.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.update_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_update_product_set_from_dict(): - test_update_product_set(request_type=dict) - - -def test_update_product_set_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 = ProductSearchClient( - 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.update_product_set), - '__call__') as call: - client.update_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - -@pytest.mark.asyncio -async def test_update_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductSetRequest): - client = ProductSearchAsyncClient( - 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.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.update_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_update_product_set_async_from_dict(): - await test_update_product_set_async(request_type=dict) - - -def test_update_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.UpdateProductSetRequest() - - request.product_set.name = 'product_set.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.update_product_set(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', - 'product_set.name=product_set.name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.UpdateProductSetRequest() - - request.product_set.name = 'product_set.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.update_product_set(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', - 'product_set.name=product_set.name/value', - ) in kw['metadata'] - - -def test_update_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product_set( - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -def test_update_product_set_flattened_error(): - client = ProductSearchClient( - 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.update_product_set( - product_search_service.UpdateProductSetRequest(), - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.asyncio -async def test_update_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product_set( - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -@pytest.mark.asyncio -async def test_update_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.update_product_set( - product_search_service.UpdateProductSetRequest(), - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product_set(transport: str = 'grpc', request_type=product_search_service.DeleteProductSetRequest): - client = ProductSearchClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_set_from_dict(): - test_delete_product_set(request_type=dict) - - -def test_delete_product_set_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 = ProductSearchClient( - 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_product_set), - '__call__') as call: - client.delete_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - -@pytest.mark.asyncio -async def test_delete_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductSetRequest): - client = ProductSearchAsyncClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_set_async_from_dict(): - await test_delete_product_set_async(request_type=dict) - - -def test_delete_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - call.return_value = None - client.delete_product_set(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_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product_set(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_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product_set( - 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_product_set_flattened_error(): - client = ProductSearchClient( - 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_product_set( - product_search_service.DeleteProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product_set( - 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_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_set( - product_search_service.DeleteProductSetRequest(), - name='name_value', - ) - - -def test_create_product(transport: str = 'grpc', request_type=product_search_service.CreateProductRequest): - client = ProductSearchClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.create_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_create_product_from_dict(): - test_create_product(request_type=dict) - - -def test_create_product_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 = ProductSearchClient( - 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_product), - '__call__') as call: - client.create_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - -@pytest.mark.asyncio -async def test_create_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductRequest): - client = ProductSearchAsyncClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.create_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_create_product_async_from_dict(): - await test_create_product_async(request_type=dict) - - -def test_create_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateProductRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.create_product(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_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateProductRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.create_product(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_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_product( - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_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].product == product_search_service.Product(name='name_value') - assert args[0].product_id == 'product_id_value' - - -def test_create_product_flattened_error(): - client = ProductSearchClient( - 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_product( - product_search_service.CreateProductRequest(), - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_product( - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_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].product == product_search_service.Product(name='name_value') - assert args[0].product_id == 'product_id_value' - - -@pytest.mark.asyncio -async def test_create_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product( - product_search_service.CreateProductRequest(), - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_value', - ) - - -def test_list_products(transport: str = 'grpc', request_type=product_search_service.ListProductsRequest): - client = ProductSearchClient( - 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_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_from_dict(): - test_list_products(request_type=dict) - - -def test_list_products_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 = ProductSearchClient( - 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_products), - '__call__') as call: - client.list_products() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - -@pytest.mark.asyncio -async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsRequest): - client = ProductSearchAsyncClient( - 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_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_async_from_dict(): - await test_list_products_async(request_type=dict) - - -def test_list_products_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = product_search_service.ListProductsResponse() - client.list_products(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_products_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) - await client.list_products(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_products_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products( - 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_products_flattened_error(): - client = ProductSearchClient( - 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_products( - product_search_service.ListProductsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_products_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products( - 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_products_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_products( - product_search_service.ListProductsRequest(), - parent='parent_value', - ) - - -def test_list_products_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_products(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.Product) - for i in results) - -def test_list_products_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products(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_products_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products(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, product_search_service.Product) - for i in responses) - -@pytest.mark.asyncio -async def test_list_products_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_products(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_product(transport: str = 'grpc', request_type=product_search_service.GetProductRequest): - client = ProductSearchClient( - 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.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_get_product_from_dict(): - test_get_product(request_type=dict) - - -def test_get_product_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 = ProductSearchClient( - 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.get_product), - '__call__') as call: - client.get_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - -@pytest.mark.asyncio -async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductRequest): - client = ProductSearchAsyncClient( - 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.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_get_product_async_from_dict(): - await test_get_product_async(request_type=dict) - - -def test_get_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.get_product(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_get_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.get_product(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_get_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product( - 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_get_product_flattened_error(): - client = ProductSearchClient( - 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.get_product( - product_search_service.GetProductRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product( - 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_get_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_product( - product_search_service.GetProductRequest(), - name='name_value', - ) - - -def test_update_product(transport: str = 'grpc', request_type=product_search_service.UpdateProductRequest): - client = ProductSearchClient( - 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.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.update_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_update_product_from_dict(): - test_update_product(request_type=dict) - - -def test_update_product_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 = ProductSearchClient( - 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.update_product), - '__call__') as call: - client.update_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - -@pytest.mark.asyncio -async def test_update_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductRequest): - client = ProductSearchAsyncClient( - 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.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.update_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_update_product_async_from_dict(): - await test_update_product_async(request_type=dict) - - -def test_update_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.UpdateProductRequest() - - request.product.name = 'product.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.update_product(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', - 'product.name=product.name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.UpdateProductRequest() - - request.product.name = 'product.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.update_product(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', - 'product.name=product.name/value', - ) in kw['metadata'] - - -def test_update_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product( - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -def test_update_product_flattened_error(): - client = ProductSearchClient( - 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.update_product( - product_search_service.UpdateProductRequest(), - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.asyncio -async def test_update_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product( - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -@pytest.mark.asyncio -async def test_update_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.update_product( - product_search_service.UpdateProductRequest(), - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product(transport: str = 'grpc', request_type=product_search_service.DeleteProductRequest): - client = ProductSearchClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_from_dict(): - test_delete_product(request_type=dict) - - -def test_delete_product_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 = ProductSearchClient( - 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_product), - '__call__') as call: - client.delete_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - -@pytest.mark.asyncio -async def test_delete_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductRequest): - client = ProductSearchAsyncClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_async_from_dict(): - await test_delete_product_async(request_type=dict) - - -def test_delete_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - call.return_value = None - client.delete_product(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_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product(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_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product( - 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_product_flattened_error(): - client = ProductSearchClient( - 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_product( - product_search_service.DeleteProductRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product( - 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_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product( - product_search_service.DeleteProductRequest(), - name='name_value', - ) - - -def test_create_reference_image(transport: str = 'grpc', request_type=product_search_service.CreateReferenceImageRequest): - client = ProductSearchClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - ) - response = client.create_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -def test_create_reference_image_from_dict(): - test_create_reference_image(request_type=dict) - - -def test_create_reference_image_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 = ProductSearchClient( - 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_reference_image), - '__call__') as call: - client.create_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_create_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateReferenceImageRequest): - client = ProductSearchAsyncClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - )) - response = await client.create_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -@pytest.mark.asyncio -async def test_create_reference_image_async_from_dict(): - await test_create_reference_image_async(request_type=dict) - - -def test_create_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateReferenceImageRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - call.return_value = product_search_service.ReferenceImage() - client.create_reference_image(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_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateReferenceImageRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - await client.create_reference_image(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_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_reference_image( - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') - assert args[0].reference_image_id == 'reference_image_id_value' - - -def test_create_reference_image_flattened_error(): - client = ProductSearchClient( - 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_reference_image( - product_search_service.CreateReferenceImageRequest(), - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_reference_image( - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') - assert args[0].reference_image_id == 'reference_image_id_value' - - -@pytest.mark.asyncio -async def test_create_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_image( - product_search_service.CreateReferenceImageRequest(), - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_value', - ) - - -def test_delete_reference_image(transport: str = 'grpc', request_type=product_search_service.DeleteReferenceImageRequest): - client = ProductSearchClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_reference_image_from_dict(): - test_delete_reference_image(request_type=dict) - - -def test_delete_reference_image_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 = ProductSearchClient( - 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_reference_image), - '__call__') as call: - client.delete_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_delete_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteReferenceImageRequest): - client = ProductSearchAsyncClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_reference_image_async_from_dict(): - await test_delete_reference_image_async(request_type=dict) - - -def test_delete_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - call.return_value = None - client.delete_reference_image(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_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_reference_image(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_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_reference_image( - 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_reference_image_flattened_error(): - client = ProductSearchClient( - 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_reference_image( - product_search_service.DeleteReferenceImageRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_reference_image( - 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_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_image( - product_search_service.DeleteReferenceImageRequest(), - name='name_value', - ) - - -def test_list_reference_images(transport: str = 'grpc', request_type=product_search_service.ListReferenceImagesRequest): - client = ProductSearchClient( - 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_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse( - page_size=951, - next_page_token='next_page_token_value', - ) - response = client.list_reference_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReferenceImagesPager) - assert response.page_size == 951 - assert response.next_page_token == 'next_page_token_value' - - -def test_list_reference_images_from_dict(): - test_list_reference_images(request_type=dict) - - -def test_list_reference_images_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 = ProductSearchClient( - 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_reference_images), - '__call__') as call: - client.list_reference_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - -@pytest.mark.asyncio -async def test_list_reference_images_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListReferenceImagesRequest): - client = ProductSearchAsyncClient( - 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_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse( - page_size=951, - next_page_token='next_page_token_value', - )) - response = await client.list_reference_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReferenceImagesAsyncPager) - assert response.page_size == 951 - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_reference_images_async_from_dict(): - await test_list_reference_images_async(request_type=dict) - - -def test_list_reference_images_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListReferenceImagesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - call.return_value = product_search_service.ListReferenceImagesResponse() - client.list_reference_images(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_reference_images_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListReferenceImagesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) - await client.list_reference_images(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_reference_images_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_reference_images( - 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_reference_images_flattened_error(): - client = ProductSearchClient( - 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_reference_images( - product_search_service.ListReferenceImagesRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_reference_images_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_reference_images( - 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_reference_images_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_images( - product_search_service.ListReferenceImagesRequest(), - parent='parent_value', - ) - - -def test_list_reference_images_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_reference_images(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.ReferenceImage) - for i in results) - -def test_list_reference_images_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - pages = list(client.list_reference_images(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_reference_images_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_reference_images(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, product_search_service.ReferenceImage) - for i in responses) - -@pytest.mark.asyncio -async def test_list_reference_images_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_reference_images(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_reference_image(transport: str = 'grpc', request_type=product_search_service.GetReferenceImageRequest): - client = ProductSearchClient( - 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.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - ) - response = client.get_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -def test_get_reference_image_from_dict(): - test_get_reference_image(request_type=dict) - - -def test_get_reference_image_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 = ProductSearchClient( - 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.get_reference_image), - '__call__') as call: - client.get_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_get_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetReferenceImageRequest): - client = ProductSearchAsyncClient( - 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.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - )) - response = await client.get_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -@pytest.mark.asyncio -async def test_get_reference_image_async_from_dict(): - await test_get_reference_image_async(request_type=dict) - - -def test_get_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - call.return_value = product_search_service.ReferenceImage() - client.get_reference_image(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_get_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - await client.get_reference_image(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_get_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_reference_image( - 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_get_reference_image_flattened_error(): - client = ProductSearchClient( - 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.get_reference_image( - product_search_service.GetReferenceImageRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_reference_image( - 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_get_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_reference_image( - product_search_service.GetReferenceImageRequest(), - name='name_value', - ) - - -def test_add_product_to_product_set(transport: str = 'grpc', request_type=product_search_service.AddProductToProductSetRequest): - client = ProductSearchClient( - 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.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.add_product_to_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_add_product_to_product_set_from_dict(): - test_add_product_to_product_set(request_type=dict) - - -def test_add_product_to_product_set_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 = ProductSearchClient( - 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.add_product_to_product_set), - '__call__') as call: - client.add_product_to_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.AddProductToProductSetRequest): - client = ProductSearchAsyncClient( - 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.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.add_product_to_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_async_from_dict(): - await test_add_product_to_product_set_async(request_type=dict) - - -def test_add_product_to_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.AddProductToProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - call.return_value = None - client.add_product_to_product_set(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_add_product_to_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.AddProductToProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.add_product_to_product_set(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_add_product_to_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.add_product_to_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -def test_add_product_to_product_set_flattened_error(): - client = ProductSearchClient( - 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.add_product_to_product_set( - product_search_service.AddProductToProductSetRequest(), - name='name_value', - product='product_value', - ) - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.add_product_to_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.add_product_to_product_set( - product_search_service.AddProductToProductSetRequest(), - name='name_value', - product='product_value', - ) - - -def test_remove_product_from_product_set(transport: str = 'grpc', request_type=product_search_service.RemoveProductFromProductSetRequest): - client = ProductSearchClient( - 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.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.remove_product_from_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_remove_product_from_product_set_from_dict(): - test_remove_product_from_product_set(request_type=dict) - - -def test_remove_product_from_product_set_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 = ProductSearchClient( - 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.remove_product_from_product_set), - '__call__') as call: - client.remove_product_from_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.RemoveProductFromProductSetRequest): - client = ProductSearchAsyncClient( - 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.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.remove_product_from_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_async_from_dict(): - await test_remove_product_from_product_set_async(request_type=dict) - - -def test_remove_product_from_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.RemoveProductFromProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - call.return_value = None - client.remove_product_from_product_set(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_remove_product_from_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.RemoveProductFromProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.remove_product_from_product_set(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_remove_product_from_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.remove_product_from_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -def test_remove_product_from_product_set_flattened_error(): - client = ProductSearchClient( - 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.remove_product_from_product_set( - product_search_service.RemoveProductFromProductSetRequest(), - name='name_value', - product='product_value', - ) - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.remove_product_from_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.remove_product_from_product_set( - product_search_service.RemoveProductFromProductSetRequest(), - name='name_value', - product='product_value', - ) - - -def test_list_products_in_product_set(transport: str = 'grpc', request_type=product_search_service.ListProductsInProductSetRequest): - client = ProductSearchClient( - 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_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products_in_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsInProductSetPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_in_product_set_from_dict(): - test_list_products_in_product_set(request_type=dict) - - -def test_list_products_in_product_set_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 = ProductSearchClient( - 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_products_in_product_set), - '__call__') as call: - client.list_products_in_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsInProductSetRequest): - client = ProductSearchAsyncClient( - 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_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products_in_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsInProductSetAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async_from_dict(): - await test_list_products_in_product_set_async(request_type=dict) - - -def test_list_products_in_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductsInProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - call.return_value = product_search_service.ListProductsInProductSetResponse() - client.list_products_in_product_set(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_list_products_in_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductsInProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) - await client.list_products_in_product_set(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_list_products_in_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products_in_product_set( - 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_list_products_in_product_set_flattened_error(): - client = ProductSearchClient( - 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_products_in_product_set( - product_search_service.ListProductsInProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products_in_product_set( - 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_list_products_in_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_products_in_product_set( - product_search_service.ListProductsInProductSetRequest(), - name='name_value', - ) - - -def test_list_products_in_product_set_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('name', ''), - )), - ) - pager = client.list_products_in_product_set(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.Product) - for i in results) - -def test_list_products_in_product_set_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products_in_product_set(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_products_in_product_set_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products_in_product_set(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, product_search_service.Product) - for i in responses) - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_products_in_product_set(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_import_product_sets(transport: str = 'grpc', request_type=product_search_service.ImportProductSetsRequest): - client = ProductSearchClient( - 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.import_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.import_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_import_product_sets_from_dict(): - test_import_product_sets(request_type=dict) - - -def test_import_product_sets_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 = ProductSearchClient( - 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.import_product_sets), - '__call__') as call: - client.import_product_sets() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - -@pytest.mark.asyncio -async def test_import_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ImportProductSetsRequest): - client = ProductSearchAsyncClient( - 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.import_product_sets), - '__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.import_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_import_product_sets_async_from_dict(): - await test_import_product_sets_async(request_type=dict) - - -def test_import_product_sets_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ImportProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.import_product_sets(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_import_product_sets_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ImportProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.import_product_sets(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_import_product_sets_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__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.import_product_sets( - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) - - -def test_import_product_sets_flattened_error(): - client = ProductSearchClient( - 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.import_product_sets( - product_search_service.ImportProductSetsRequest(), - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), - ) - - -@pytest.mark.asyncio -async def test_import_product_sets_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__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.import_product_sets( - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) - - -@pytest.mark.asyncio -async def test_import_product_sets_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.import_product_sets( - product_search_service.ImportProductSetsRequest(), - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), - ) - - -def test_purge_products(transport: str = 'grpc', request_type=product_search_service.PurgeProductsRequest): - client = ProductSearchClient( - 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.purge_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.purge_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.PurgeProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_purge_products_from_dict(): - test_purge_products(request_type=dict) - - -def test_purge_products_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 = ProductSearchClient( - 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.purge_products), - '__call__') as call: - client.purge_products() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.PurgeProductsRequest() - - -@pytest.mark.asyncio -async def test_purge_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.PurgeProductsRequest): - client = ProductSearchAsyncClient( - 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.purge_products), - '__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.purge_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.PurgeProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_purge_products_async_from_dict(): - await test_purge_products_async(request_type=dict) - - -def test_purge_products_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.PurgeProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.purge_products(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_purge_products_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.PurgeProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.purge_products(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_purge_products_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__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.purge_products( - 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_purge_products_flattened_error(): - client = ProductSearchClient( - 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.purge_products( - product_search_service.PurgeProductsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_purge_products_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__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.purge_products( - 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_purge_products_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.purge_products( - product_search_service.PurgeProductsRequest(), - parent='parent_value', - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ProductSearchClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ProductSearchGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, -]) -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 = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ProductSearchGrpcTransport, - ) - -def test_product_search_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ProductSearchTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_product_search_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1.services.product_search.transports.ProductSearchTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ProductSearchTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'create_product_set', - 'list_product_sets', - 'get_product_set', - 'update_product_set', - 'delete_product_set', - 'create_product', - 'list_products', - 'get_product', - 'update_product', - 'delete_product', - 'create_reference_image', - 'delete_reference_image', - 'list_reference_images', - 'get_reference_image', - 'add_product_to_product_set', - 'remove_product_from_product_set', - 'list_products_in_product_set', - 'import_product_sets', - 'purge_products', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_product_search_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.vision_v1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_product_search_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_product_search_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ProductSearchGrpcTransport, grpc_helpers), - (transports.ProductSearchGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_product_search_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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_product_search_host_no_port(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_product_search_host_with_port(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_product_search_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductSearchGrpcTransport( - 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_product_search_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductSearchGrpcAsyncIOTransport( - 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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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_product_search_grpc_lro_client(): - client = ProductSearchClient( - 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_product_search_grpc_lro_async_client(): - client = ProductSearchAsyncClient( - 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_product_path(): - project = "squid" - location = "clam" - product = "whelk" - expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - actual = ProductSearchClient.product_path(project, location, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "project": "octopus", - "location": "oyster", - "product": "nudibranch", - } - path = ProductSearchClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_product_path(path) - assert expected == actual - -def test_product_set_path(): - project = "cuttlefish" - location = "mussel" - product_set = "winkle" - expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - actual = ProductSearchClient.product_set_path(project, location, product_set) - assert expected == actual - - -def test_parse_product_set_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "product_set": "abalone", - } - path = ProductSearchClient.product_set_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_product_set_path(path) - assert expected == actual - -def test_reference_image_path(): - project = "squid" - location = "clam" - product = "whelk" - reference_image = "octopus" - expected = "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) - actual = ProductSearchClient.reference_image_path(project, location, product, reference_image) - assert expected == actual - - -def test_parse_reference_image_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "product": "cuttlefish", - "reference_image": "mussel", - } - path = ProductSearchClient.reference_image_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_reference_image_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ProductSearchClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nautilus", - } - path = ProductSearchClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "scallop" - expected = "folders/{folder}".format(folder=folder, ) - actual = ProductSearchClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "abalone", - } - path = ProductSearchClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "squid" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ProductSearchClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "clam", - } - path = ProductSearchClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "whelk" - expected = "projects/{project}".format(project=project, ) - actual = ProductSearchClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "octopus", - } - path = ProductSearchClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "oyster" - location = "nudibranch" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = ProductSearchClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - } - path = ProductSearchClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.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.ProductSearchTransport, '_prep_wrapped_messages') as prep: - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ProductSearchTransport, '_prep_wrapped_messages') as prep: - transport_class = ProductSearchClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1p1beta1/.coveragerc b/owl-bot-staging/v1p1beta1/.coveragerc deleted file mode 100644 index 75747063..00000000 --- a/owl-bot-staging/v1p1beta1/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/vision/__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/v1p1beta1/MANIFEST.in b/owl-bot-staging/v1p1beta1/MANIFEST.in deleted file mode 100644 index 7fd81c6f..00000000 --- a/owl-bot-staging/v1p1beta1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/vision *.py -recursive-include google/cloud/vision_v1p1beta1 *.py diff --git a/owl-bot-staging/v1p1beta1/README.rst b/owl-bot-staging/v1p1beta1/README.rst deleted file mode 100644 index 39f9ca72..00000000 --- a/owl-bot-staging/v1p1beta1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Vision 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 Vision 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/v1p1beta1/docs/conf.py b/owl-bot-staging/v1p1beta1/docs/conf.py deleted file mode 100644 index 6e730bf5..00000000 --- a/owl-bot-staging/v1p1beta1/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-vision 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-vision" -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-vision-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-vision.tex", - u"google-cloud-vision 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-vision", - u"Google Cloud Vision 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-vision", - u"google-cloud-vision Documentation", - author, - "google-cloud-vision", - "GAPIC library for Google Cloud Vision 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/v1p1beta1/docs/index.rst b/owl-bot-staging/v1p1beta1/docs/index.rst deleted file mode 100644 index 049cf367..00000000 --- a/owl-bot-staging/v1p1beta1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - vision_v1p1beta1/services - vision_v1p1beta1/types diff --git a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst deleted file mode 100644 index 4aa9e5a2..00000000 --- a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/image_annotator.rst +++ /dev/null @@ -1,6 +0,0 @@ -ImageAnnotator --------------------------------- - -.. automodule:: google.cloud.vision_v1p1beta1.services.image_annotator - :members: - :inherited-members: diff --git a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst deleted file mode 100644 index 1b046a84..00000000 --- a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Vision v1p1beta1 API -============================================== -.. toctree:: - :maxdepth: 2 - - image_annotator diff --git a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst b/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst deleted file mode 100644 index 11b2290f..00000000 --- a/owl-bot-staging/v1p1beta1/docs/vision_v1p1beta1/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Vision v1p1beta1 API -=========================================== - -.. automodule:: google.cloud.vision_v1p1beta1.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py deleted file mode 100644 index efb3365d..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision/__init__.py +++ /dev/null @@ -1,89 +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.vision_v1p1beta1.services.image_annotator.client import ImageAnnotatorClient -from google.cloud.vision_v1p1beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient - -from google.cloud.vision_v1p1beta1.types.geometry import BoundingPoly -from google.cloud.vision_v1p1beta1.types.geometry import Position -from google.cloud.vision_v1p1beta1.types.geometry import Vertex -from google.cloud.vision_v1p1beta1.types.image_annotator import AnnotateImageRequest -from google.cloud.vision_v1p1beta1.types.image_annotator import AnnotateImageResponse -from google.cloud.vision_v1p1beta1.types.image_annotator import BatchAnnotateImagesRequest -from google.cloud.vision_v1p1beta1.types.image_annotator import BatchAnnotateImagesResponse -from google.cloud.vision_v1p1beta1.types.image_annotator import ColorInfo -from google.cloud.vision_v1p1beta1.types.image_annotator import CropHint -from google.cloud.vision_v1p1beta1.types.image_annotator import CropHintsAnnotation -from google.cloud.vision_v1p1beta1.types.image_annotator import CropHintsParams -from google.cloud.vision_v1p1beta1.types.image_annotator import DominantColorsAnnotation -from google.cloud.vision_v1p1beta1.types.image_annotator import EntityAnnotation -from google.cloud.vision_v1p1beta1.types.image_annotator import FaceAnnotation -from google.cloud.vision_v1p1beta1.types.image_annotator import Feature -from google.cloud.vision_v1p1beta1.types.image_annotator import Image -from google.cloud.vision_v1p1beta1.types.image_annotator import ImageContext -from google.cloud.vision_v1p1beta1.types.image_annotator import ImageProperties -from google.cloud.vision_v1p1beta1.types.image_annotator import ImageSource -from google.cloud.vision_v1p1beta1.types.image_annotator import LatLongRect -from google.cloud.vision_v1p1beta1.types.image_annotator import LocationInfo -from google.cloud.vision_v1p1beta1.types.image_annotator import Property -from google.cloud.vision_v1p1beta1.types.image_annotator import SafeSearchAnnotation -from google.cloud.vision_v1p1beta1.types.image_annotator import TextDetectionParams -from google.cloud.vision_v1p1beta1.types.image_annotator import WebDetectionParams -from google.cloud.vision_v1p1beta1.types.image_annotator import Likelihood -from google.cloud.vision_v1p1beta1.types.text_annotation import Block -from google.cloud.vision_v1p1beta1.types.text_annotation import Page -from google.cloud.vision_v1p1beta1.types.text_annotation import Paragraph -from google.cloud.vision_v1p1beta1.types.text_annotation import Symbol -from google.cloud.vision_v1p1beta1.types.text_annotation import TextAnnotation -from google.cloud.vision_v1p1beta1.types.text_annotation import Word -from google.cloud.vision_v1p1beta1.types.web_detection import WebDetection - -__all__ = ('ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', - 'BoundingPoly', - 'Position', - 'Vertex', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'Image', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'LatLongRect', - 'LocationInfo', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py deleted file mode 100644 index a0b8efb9..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/__init__.py +++ /dev/null @@ -1,90 +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.image_annotator import ImageAnnotatorClient -from .services.image_annotator import ImageAnnotatorAsyncClient - -from .types.geometry import BoundingPoly -from .types.geometry import Position -from .types.geometry import Vertex -from .types.image_annotator import AnnotateImageRequest -from .types.image_annotator import AnnotateImageResponse -from .types.image_annotator import BatchAnnotateImagesRequest -from .types.image_annotator import BatchAnnotateImagesResponse -from .types.image_annotator import ColorInfo -from .types.image_annotator import CropHint -from .types.image_annotator import CropHintsAnnotation -from .types.image_annotator import CropHintsParams -from .types.image_annotator import DominantColorsAnnotation -from .types.image_annotator import EntityAnnotation -from .types.image_annotator import FaceAnnotation -from .types.image_annotator import Feature -from .types.image_annotator import Image -from .types.image_annotator import ImageContext -from .types.image_annotator import ImageProperties -from .types.image_annotator import ImageSource -from .types.image_annotator import LatLongRect -from .types.image_annotator import LocationInfo -from .types.image_annotator import Property -from .types.image_annotator import SafeSearchAnnotation -from .types.image_annotator import TextDetectionParams -from .types.image_annotator import WebDetectionParams -from .types.image_annotator import Likelihood -from .types.text_annotation import Block -from .types.text_annotation import Page -from .types.text_annotation import Paragraph -from .types.text_annotation import Symbol -from .types.text_annotation import TextAnnotation -from .types.text_annotation import Word -from .types.web_detection import WebDetection - -__all__ = ( - 'ImageAnnotatorAsyncClient', -'AnnotateImageRequest', -'AnnotateImageResponse', -'BatchAnnotateImagesRequest', -'BatchAnnotateImagesResponse', -'Block', -'BoundingPoly', -'ColorInfo', -'CropHint', -'CropHintsAnnotation', -'CropHintsParams', -'DominantColorsAnnotation', -'EntityAnnotation', -'FaceAnnotation', -'Feature', -'Image', -'ImageAnnotatorClient', -'ImageContext', -'ImageProperties', -'ImageSource', -'LatLongRect', -'Likelihood', -'LocationInfo', -'Page', -'Paragraph', -'Position', -'Property', -'SafeSearchAnnotation', -'Symbol', -'TextAnnotation', -'TextDetectionParams', -'Vertex', -'WebDetection', -'WebDetectionParams', -'Word', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json deleted file mode 100644 index b198d92f..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/gapic_metadata.json +++ /dev/null @@ -1,33 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.vision_v1p1beta1", - "protoPackage": "google.cloud.vision.v1p1beta1", - "schema": "1.0", - "services": { - "ImageAnnotator": { - "clients": { - "grpc": { - "libraryClient": "ImageAnnotatorClient", - "rpcs": { - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ImageAnnotatorAsyncClient", - "rpcs": { - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/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/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__init__.py deleted file mode 100644 index 3cbfa2fa..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/__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 ImageAnnotatorClient -from .async_client import ImageAnnotatorAsyncClient - -__all__ = ( - 'ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py deleted file mode 100644 index f439455d..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/async_client.py +++ /dev/null @@ -1,241 +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.cloud.vision_v1p1beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport -from .client import ImageAnnotatorClient - - -class ImageAnnotatorAsyncClient: - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - _client: ImageAnnotatorClient - - DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT - - common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) - parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) - common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) - parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) - common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) - parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) - common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) - parse_common_location_path = staticmethod(ImageAnnotatorClient.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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def batch_annotate_images(self, - request: image_annotator.BatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (:class:`google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest`): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]`): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1p1beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorAsyncClient", -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py deleted file mode 100644 index 0f1ae394..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/client.py +++ /dev/null @@ -1,422 +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 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.cloud.vision_v1p1beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ImageAnnotatorGrpcTransport -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -class ImageAnnotatorClientMeta(type): - """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] - _transport_registry["grpc"] = ImageAnnotatorGrpcTransport - _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ImageAnnotatorTransport]: - """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - @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 = "vision.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: - ImageAnnotatorClient: 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: - ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: 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, ImageAnnotatorTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): - # transport is a ImageAnnotatorTransport 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, - always_use_jwt_access=True, - ) - - def batch_annotate_images(self, - request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (Union[google.cloud.vision_v1p1beta1.types.BatchAnnotateImagesRequest, dict]): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1p1beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 image_annotator.BatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): - request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorClient", -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/__init__.py deleted file mode 100644 index 94f01250..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/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 ImageAnnotatorTransport -from .grpc import ImageAnnotatorGrpcTransport -from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] -_transport_registry['grpc'] = ImageAnnotatorGrpcTransport -_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport - -__all__ = ( - 'ImageAnnotatorTransport', - 'ImageAnnotatorGrpcTransport', - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py deleted file mode 100644 index ebb9e3b0..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/base.py +++ /dev/null @@ -1,185 +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.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.vision_v1p1beta1.types import image_annotator - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-vision', - ).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 ImageAnnotatorTransport(abc.ABC): - """Abstract transport class for ImageAnnotator.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( - self.batch_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Union[ - image_annotator.BatchAnnotateImagesResponse, - Awaitable[image_annotator.BatchAnnotateImagesResponse] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ImageAnnotatorTransport', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py deleted file mode 100644 index d8544cb2..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc.py +++ /dev/null @@ -1,258 +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 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.vision_v1p1beta1.types import image_annotator -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO - - -class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): - """gRPC backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 application 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 the 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 a 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] = {} - - 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 = 'vision.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 batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - image_annotator.BatchAnnotateImagesResponse]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - ~.BatchAnnotateImagesResponse]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p1beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ImageAnnotatorGrpcTransport', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py deleted file mode 100644 index 50e4218f..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/services/image_annotator/transports/grpc_asyncio.py +++ /dev/null @@ -1,263 +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.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.vision_v1p1beta1.types import image_annotator -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .grpc import ImageAnnotatorGrpcTransport - - -class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): - """gRPC AsyncIO backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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] = {} - - 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 batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Awaitable[image_annotator.BatchAnnotateImagesResponse]]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - Awaitable[~.BatchAnnotateImagesResponse]]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p1beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py deleted file mode 100644 index ec92dd01..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/__init__.py +++ /dev/null @@ -1,92 +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 .geometry import ( - BoundingPoly, - Position, - Vertex, -) -from .image_annotator import ( - AnnotateImageRequest, - AnnotateImageResponse, - BatchAnnotateImagesRequest, - BatchAnnotateImagesResponse, - ColorInfo, - CropHint, - CropHintsAnnotation, - CropHintsParams, - DominantColorsAnnotation, - EntityAnnotation, - FaceAnnotation, - Feature, - Image, - ImageContext, - ImageProperties, - ImageSource, - LatLongRect, - LocationInfo, - Property, - SafeSearchAnnotation, - TextDetectionParams, - WebDetectionParams, - Likelihood, -) -from .text_annotation import ( - Block, - Page, - Paragraph, - Symbol, - TextAnnotation, - Word, -) -from .web_detection import ( - WebDetection, -) - -__all__ = ( - 'BoundingPoly', - 'Position', - 'Vertex', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'Image', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'LatLongRect', - 'LocationInfo', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py deleted file mode 100644 index eafc97e6..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/geometry.py +++ /dev/null @@ -1,95 +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.vision.v1p1beta1', - manifest={ - 'Vertex', - 'BoundingPoly', - 'Position', - }, -) - - -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 BoundingPoly(proto.Message): - r"""A bounding polygon for the detected image annotation. - - Attributes: - vertices (Sequence[google.cloud.vision_v1p1beta1.types.Vertex]): - The bounding polygon vertices. - """ - - vertices = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Vertex', - ) - - -class Position(proto.Message): - r"""A 3D position in the image, used primarily for Face detection - landmarks. A valid Position must have both x and y coordinates. - The position coordinates are in the same scale as the original - image. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate. - z (float): - Z coordinate (or depth). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - z = proto.Field( - proto.FLOAT, - number=3, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py deleted file mode 100644 index 42cecd96..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/image_annotator.py +++ /dev/null @@ -1,947 +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.vision_v1p1beta1.types import geometry -from google.cloud.vision_v1p1beta1.types import text_annotation -from google.cloud.vision_v1p1beta1.types import web_detection as gcv_web_detection -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import latlng_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p1beta1', - manifest={ - 'Likelihood', - 'Feature', - 'ImageSource', - 'Image', - 'FaceAnnotation', - 'LocationInfo', - 'Property', - 'EntityAnnotation', - 'SafeSearchAnnotation', - 'LatLongRect', - 'ColorInfo', - 'DominantColorsAnnotation', - 'ImageProperties', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'WebDetectionParams', - 'TextDetectionParams', - 'ImageContext', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - }, -) - - -class Likelihood(proto.Enum): - r"""A bucketized representation of likelihood, which is intended - to give clients highly stable results across model upgrades. - """ - UNKNOWN = 0 - VERY_UNLIKELY = 1 - UNLIKELY = 2 - POSSIBLE = 3 - LIKELY = 4 - VERY_LIKELY = 5 - - -class Feature(proto.Message): - r"""Users describe the type of Google Cloud Vision API tasks to perform - over images by using *Feature*\ s. Each Feature indicates a type of - image detection task to perform. Features encode the Cloud Vision - API vertical to operate on and the number of top-scoring results to - return. - - Attributes: - type_ (google.cloud.vision_v1p1beta1.types.Feature.Type): - The feature type. - max_results (int): - Maximum number of results of this type. - model (str): - Model to use for the feature. - Supported values: "builtin/stable" (the default - if unset) and "builtin/latest". - """ - class Type(proto.Enum): - r"""Type of image feature.""" - TYPE_UNSPECIFIED = 0 - FACE_DETECTION = 1 - LANDMARK_DETECTION = 2 - LOGO_DETECTION = 3 - LABEL_DETECTION = 4 - TEXT_DETECTION = 5 - DOCUMENT_TEXT_DETECTION = 11 - SAFE_SEARCH_DETECTION = 6 - IMAGE_PROPERTIES = 7 - CROP_HINTS = 9 - WEB_DETECTION = 10 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum=Type, - ) - max_results = proto.Field( - proto.INT32, - number=2, - ) - model = proto.Field( - proto.STRING, - number=3, - ) - - -class ImageSource(proto.Message): - r"""External image source (Google Cloud Storage image location). - - Attributes: - gcs_image_uri (str): - NOTE: For new code ``image_uri`` below is preferred. Google - Cloud Storage image URI, which must be in the following - form: ``gs://bucket_name/object_name`` (for details, see - `Google Cloud Storage Request - URIs `__). - NOTE: Cloud Storage object versioning is not supported. - image_uri (str): - Image URI which supports: - - 1) Google Cloud Storage image URI, which must be in the - following form: ``gs://bucket_name/object_name`` (for - details, see `Google Cloud Storage Request - URIs `__). - NOTE: Cloud Storage object versioning is not supported. - 2) Publicly accessible image HTTP/HTTPS URL. This is - preferred over the legacy ``gcs_image_uri`` above. When - both ``gcs_image_uri`` and ``image_uri`` are specified, - ``image_uri`` takes precedence. - """ - - gcs_image_uri = proto.Field( - proto.STRING, - number=1, - ) - image_uri = proto.Field( - proto.STRING, - number=2, - ) - - -class Image(proto.Message): - r"""Client image to perform Google Cloud Vision API tasks over. - - Attributes: - content (bytes): - Image content, represented as a stream of bytes. Note: as - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - source (google.cloud.vision_v1p1beta1.types.ImageSource): - Google Cloud Storage image location. If both ``content`` and - ``source`` are provided for an image, ``content`` takes - precedence and is used to perform the image annotation - request. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - source = proto.Field( - proto.MESSAGE, - number=2, - message='ImageSource', - ) - - -class FaceAnnotation(proto.Message): - r"""A face annotation object contains the results of face - detection. - - Attributes: - bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The bounding polygon around the face. The coordinates of the - bounding box are in the original image's scale, as returned - in ``ImageParams``. The bounding box is computed to "frame" - the face in accordance with human expectations. It is based - on the landmarker results. Note that one or more x and/or y - coordinates may not be generated in the ``BoundingPoly`` - (the polygon will be unbounded) if only a partial face - appears in the image to be annotated. - fd_bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The ``fd_bounding_poly`` bounding polygon is tighter than - the ``boundingPoly``, and encloses only the skin part of the - face. Typically, it is used to eliminate the face from any - image analysis that detects the "amount of skin" visible in - an image. It is not based on the landmarker results, only on - the initial face detection, hence the fd (face detection) - prefix. - landmarks (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark]): - Detected face landmarks. - roll_angle (float): - Roll angle, which indicates the amount of - clockwise/anti-clockwise rotation of the face relative to - the image vertical about the axis perpendicular to the face. - Range [-180,180]. - pan_angle (float): - Yaw angle, which indicates the leftward/rightward angle that - the face is pointing relative to the vertical plane - perpendicular to the image. Range [-180,180]. - tilt_angle (float): - Pitch angle, which indicates the upwards/downwards angle - that the face is pointing relative to the image's horizontal - plane. Range [-180,180]. - detection_confidence (float): - Detection confidence. Range [0, 1]. - landmarking_confidence (float): - Face landmarking confidence. Range [0, 1]. - joy_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Joy likelihood. - sorrow_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Sorrow likelihood. - anger_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Anger likelihood. - surprise_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Surprise likelihood. - under_exposed_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Under-exposed likelihood. - blurred_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Blurred likelihood. - headwear_likelihood (google.cloud.vision_v1p1beta1.types.Likelihood): - Headwear likelihood. - """ - - class Landmark(proto.Message): - r"""A face-specific landmark (for example, a face feature). - - Attributes: - type_ (google.cloud.vision_v1p1beta1.types.FaceAnnotation.Landmark.Type): - Face landmark type. - position (google.cloud.vision_v1p1beta1.types.Position): - Face landmark position. - """ - class Type(proto.Enum): - r"""Face landmark (feature) type. Left and right are defined from the - vantage of the viewer of the image without considering mirror - projections typical of photos. So, ``LEFT_EYE``, typically, is the - person's right eye. - """ - UNKNOWN_LANDMARK = 0 - LEFT_EYE = 1 - RIGHT_EYE = 2 - LEFT_OF_LEFT_EYEBROW = 3 - RIGHT_OF_LEFT_EYEBROW = 4 - LEFT_OF_RIGHT_EYEBROW = 5 - RIGHT_OF_RIGHT_EYEBROW = 6 - MIDPOINT_BETWEEN_EYES = 7 - NOSE_TIP = 8 - UPPER_LIP = 9 - LOWER_LIP = 10 - MOUTH_LEFT = 11 - MOUTH_RIGHT = 12 - MOUTH_CENTER = 13 - NOSE_BOTTOM_RIGHT = 14 - NOSE_BOTTOM_LEFT = 15 - NOSE_BOTTOM_CENTER = 16 - LEFT_EYE_TOP_BOUNDARY = 17 - LEFT_EYE_RIGHT_CORNER = 18 - LEFT_EYE_BOTTOM_BOUNDARY = 19 - LEFT_EYE_LEFT_CORNER = 20 - RIGHT_EYE_TOP_BOUNDARY = 21 - RIGHT_EYE_RIGHT_CORNER = 22 - RIGHT_EYE_BOTTOM_BOUNDARY = 23 - RIGHT_EYE_LEFT_CORNER = 24 - LEFT_EYEBROW_UPPER_MIDPOINT = 25 - RIGHT_EYEBROW_UPPER_MIDPOINT = 26 - LEFT_EAR_TRAGION = 27 - RIGHT_EAR_TRAGION = 28 - LEFT_EYE_PUPIL = 29 - RIGHT_EYE_PUPIL = 30 - FOREHEAD_GLABELLA = 31 - CHIN_GNATHION = 32 - CHIN_LEFT_GONION = 33 - CHIN_RIGHT_GONION = 34 - - type_ = proto.Field( - proto.ENUM, - number=3, - enum='FaceAnnotation.Landmark.Type', - ) - position = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.Position, - ) - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - fd_bounding_poly = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - landmarks = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=Landmark, - ) - roll_angle = proto.Field( - proto.FLOAT, - number=4, - ) - pan_angle = proto.Field( - proto.FLOAT, - number=5, - ) - tilt_angle = proto.Field( - proto.FLOAT, - number=6, - ) - detection_confidence = proto.Field( - proto.FLOAT, - number=7, - ) - landmarking_confidence = proto.Field( - proto.FLOAT, - number=8, - ) - joy_likelihood = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - sorrow_likelihood = proto.Field( - proto.ENUM, - number=10, - enum='Likelihood', - ) - anger_likelihood = proto.Field( - proto.ENUM, - number=11, - enum='Likelihood', - ) - surprise_likelihood = proto.Field( - proto.ENUM, - number=12, - enum='Likelihood', - ) - under_exposed_likelihood = proto.Field( - proto.ENUM, - number=13, - enum='Likelihood', - ) - blurred_likelihood = proto.Field( - proto.ENUM, - number=14, - enum='Likelihood', - ) - headwear_likelihood = proto.Field( - proto.ENUM, - number=15, - enum='Likelihood', - ) - - -class LocationInfo(proto.Message): - r"""Detected entity location information. - - Attributes: - lat_lng (google.type.latlng_pb2.LatLng): - lat/long location coordinates. - """ - - lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - - -class Property(proto.Message): - r"""A ``Property`` consists of a user-supplied name/value pair. - - Attributes: - name (str): - Name of the property. - value (str): - Value of the property. - uint64_value (int): - Value of numeric properties. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - uint64_value = proto.Field( - proto.UINT64, - number=3, - ) - - -class EntityAnnotation(proto.Message): - r"""Set of detected entity features. - - Attributes: - mid (str): - Opaque entity ID. Some IDs may be available in `Google - Knowledge Graph Search - API `__. - locale (str): - The language code for the locale in which the entity textual - ``description`` is expressed. - description (str): - Entity textual description, expressed in its ``locale`` - language. - score (float): - Overall score of the result. Range [0, 1]. - confidence (float): - The accuracy of the entity detection in an image. For - example, for an image in which the "Eiffel Tower" entity is - detected, this field represents the confidence that there is - a tower in the query image. Range [0, 1]. - topicality (float): - The relevancy of the ICA (Image Content Annotation) label to - the image. For example, the relevancy of "tower" is likely - higher to an image containing the detected "Eiffel Tower" - than to an image containing a detected distant towering - building, even though the confidence that there is a tower - in each image may be the same. Range [0, 1]. - bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): - Image region to which this entity belongs. Not produced for - ``LABEL_DETECTION`` features. - locations (Sequence[google.cloud.vision_v1p1beta1.types.LocationInfo]): - The location information for the detected entity. Multiple - ``LocationInfo`` elements can be present because one - location may indicate the location of the scene in the - image, and another location may indicate the location of the - place where the image was taken. Location information is - usually present for landmarks. - properties (Sequence[google.cloud.vision_v1p1beta1.types.Property]): - Some entities may have optional user-supplied ``Property`` - (name/value) fields, such a score or string that qualifies - the entity. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - locale = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - topicality = proto.Field( - proto.FLOAT, - number=6, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=7, - message=geometry.BoundingPoly, - ) - locations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='LocationInfo', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Property', - ) - - -class SafeSearchAnnotation(proto.Message): - r"""Set of features pertaining to the image, computed by computer - vision methods over safe-search verticals (for example, adult, - spoof, medical, violence). - - Attributes: - adult (google.cloud.vision_v1p1beta1.types.Likelihood): - Represents the adult content likelihood for - the image. Adult content may contain elements - such as nudity, pornographic images or cartoons, - or sexual activities. - spoof (google.cloud.vision_v1p1beta1.types.Likelihood): - Spoof likelihood. The likelihood that an - modification was made to the image's canonical - version to make it appear funny or offensive. - medical (google.cloud.vision_v1p1beta1.types.Likelihood): - Likelihood that this is a medical image. - violence (google.cloud.vision_v1p1beta1.types.Likelihood): - Likelihood that this image contains violent - content. - racy (google.cloud.vision_v1p1beta1.types.Likelihood): - Likelihood that the request image contains - racy content. Racy content may include (but is - not limited to) skimpy or sheer clothing, - strategically covered nudity, lewd or - provocative poses, or close-ups of sensitive - body areas. - """ - - adult = proto.Field( - proto.ENUM, - number=1, - enum='Likelihood', - ) - spoof = proto.Field( - proto.ENUM, - number=2, - enum='Likelihood', - ) - medical = proto.Field( - proto.ENUM, - number=3, - enum='Likelihood', - ) - violence = proto.Field( - proto.ENUM, - number=4, - enum='Likelihood', - ) - racy = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - - -class LatLongRect(proto.Message): - r"""Rectangle determined by min and max ``LatLng`` pairs. - - Attributes: - min_lat_lng (google.type.latlng_pb2.LatLng): - Min lat/long pair. - max_lat_lng (google.type.latlng_pb2.LatLng): - Max lat/long pair. - """ - - min_lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - max_lat_lng = proto.Field( - proto.MESSAGE, - number=2, - message=latlng_pb2.LatLng, - ) - - -class ColorInfo(proto.Message): - r"""Color information consists of RGB channels, score, and the - fraction of the image that the color occupies in the image. - - Attributes: - color (google.type.color_pb2.Color): - RGB components of the color. - score (float): - Image-specific score for this color. Value in range [0, 1]. - pixel_fraction (float): - The fraction of pixels the color occupies in the image. - Value in range [0, 1]. - """ - - color = proto.Field( - proto.MESSAGE, - number=1, - message=color_pb2.Color, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - pixel_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class DominantColorsAnnotation(proto.Message): - r"""Set of dominant colors and their corresponding scores. - - Attributes: - colors (Sequence[google.cloud.vision_v1p1beta1.types.ColorInfo]): - RGB color values with their score and pixel - fraction. - """ - - colors = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ColorInfo', - ) - - -class ImageProperties(proto.Message): - r"""Stores image properties, such as dominant colors. - - Attributes: - dominant_colors (google.cloud.vision_v1p1beta1.types.DominantColorsAnnotation): - If present, dominant colors completed - successfully. - """ - - dominant_colors = proto.Field( - proto.MESSAGE, - number=1, - message='DominantColorsAnnotation', - ) - - -class CropHint(proto.Message): - r"""Single crop hint that is used to generate a new crop when - serving an image. - - Attributes: - bounding_poly (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The bounding polygon for the crop region. The coordinates of - the bounding box are in the original image's scale, as - returned in ``ImageParams``. - confidence (float): - Confidence of this being a salient region. Range [0, 1]. - importance_fraction (float): - Fraction of importance of this salient region - with respect to the original image. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - importance_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class CropHintsAnnotation(proto.Message): - r"""Set of crop hints that are used to generate new crops when - serving images. - - Attributes: - crop_hints (Sequence[google.cloud.vision_v1p1beta1.types.CropHint]): - Crop hint results. - """ - - crop_hints = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='CropHint', - ) - - -class CropHintsParams(proto.Message): - r"""Parameters for crop hints annotation request. - - Attributes: - aspect_ratios (Sequence[float]): - Aspect ratios in floats, representing the - ratio of the width to the height of the image. - For example, if the desired aspect ratio is 4/3, - the corresponding float value should be 1.33333. - If not specified, the best possible crop is - returned. The number of provided aspect ratios - is limited to a maximum of 16; any aspect ratios - provided after the 16th are ignored. - """ - - aspect_ratios = proto.RepeatedField( - proto.FLOAT, - number=1, - ) - - -class WebDetectionParams(proto.Message): - r"""Parameters for web detection request. - - Attributes: - include_geo_results (bool): - Whether to include results derived from the - geo information in the image. - """ - - include_geo_results = proto.Field( - proto.BOOL, - number=2, - ) - - -class TextDetectionParams(proto.Message): - r"""Parameters for text detections. This is used to control - TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. - - Attributes: - enable_text_detection_confidence_score (bool): - By default, Cloud Vision API only includes confidence score - for DOCUMENT_TEXT_DETECTION result. Set the flag to true to - include confidence score for TEXT_DETECTION as well. - """ - - enable_text_detection_confidence_score = proto.Field( - proto.BOOL, - number=9, - ) - - -class ImageContext(proto.Message): - r"""Image context and/or feature-specific parameters. - - Attributes: - lat_long_rect (google.cloud.vision_v1p1beta1.types.LatLongRect): - lat/long rectangle that specifies the - location of the image. - language_hints (Sequence[str]): - List of languages to use for TEXT_DETECTION. 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). - Text detection returns an error if one or more of the - specified languages is not one of the `supported - languages `__. - crop_hints_params (google.cloud.vision_v1p1beta1.types.CropHintsParams): - Parameters for crop hints annotation request. - web_detection_params (google.cloud.vision_v1p1beta1.types.WebDetectionParams): - Parameters for web detection. - text_detection_params (google.cloud.vision_v1p1beta1.types.TextDetectionParams): - Parameters for text detection and document - text detection. - """ - - lat_long_rect = proto.Field( - proto.MESSAGE, - number=1, - message='LatLongRect', - ) - language_hints = proto.RepeatedField( - proto.STRING, - number=2, - ) - crop_hints_params = proto.Field( - proto.MESSAGE, - number=4, - message='CropHintsParams', - ) - web_detection_params = proto.Field( - proto.MESSAGE, - number=6, - message='WebDetectionParams', - ) - text_detection_params = proto.Field( - proto.MESSAGE, - number=12, - message='TextDetectionParams', - ) - - -class AnnotateImageRequest(proto.Message): - r"""Request for performing Google Cloud Vision API tasks over a - user-provided image, with user-requested features. - - Attributes: - image (google.cloud.vision_v1p1beta1.types.Image): - The image to be processed. - features (Sequence[google.cloud.vision_v1p1beta1.types.Feature]): - Requested features. - image_context (google.cloud.vision_v1p1beta1.types.ImageContext): - Additional context that may accompany the - image. - """ - - image = proto.Field( - proto.MESSAGE, - number=1, - message='Image', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - - -class AnnotateImageResponse(proto.Message): - r"""Response to an image annotation request. - - Attributes: - face_annotations (Sequence[google.cloud.vision_v1p1beta1.types.FaceAnnotation]): - If present, face detection has completed - successfully. - landmark_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): - If present, landmark detection has completed - successfully. - logo_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): - If present, logo detection has completed - successfully. - label_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): - If present, label detection has completed - successfully. - text_annotations (Sequence[google.cloud.vision_v1p1beta1.types.EntityAnnotation]): - If present, text (OCR) detection has - completed successfully. - full_text_annotation (google.cloud.vision_v1p1beta1.types.TextAnnotation): - If present, text (OCR) detection or document - (OCR) text detection has completed successfully. - This annotation provides the structural - hierarchy for the OCR detected text. - safe_search_annotation (google.cloud.vision_v1p1beta1.types.SafeSearchAnnotation): - If present, safe-search annotation has - completed successfully. - image_properties_annotation (google.cloud.vision_v1p1beta1.types.ImageProperties): - If present, image properties were extracted - successfully. - crop_hints_annotation (google.cloud.vision_v1p1beta1.types.CropHintsAnnotation): - If present, crop hints have completed - successfully. - web_detection (google.cloud.vision_v1p1beta1.types.WebDetection): - If present, web detection has completed - successfully. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the operation. Note - that filled-in image annotations are guaranteed to be - correct, even when ``error`` is set. - """ - - face_annotations = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='FaceAnnotation', - ) - landmark_annotations = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='EntityAnnotation', - ) - logo_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='EntityAnnotation', - ) - label_annotations = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='EntityAnnotation', - ) - text_annotations = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='EntityAnnotation', - ) - full_text_annotation = proto.Field( - proto.MESSAGE, - number=12, - message=text_annotation.TextAnnotation, - ) - safe_search_annotation = proto.Field( - proto.MESSAGE, - number=6, - message='SafeSearchAnnotation', - ) - image_properties_annotation = proto.Field( - proto.MESSAGE, - number=8, - message='ImageProperties', - ) - crop_hints_annotation = proto.Field( - proto.MESSAGE, - number=11, - message='CropHintsAnnotation', - ) - web_detection = proto.Field( - proto.MESSAGE, - number=13, - message=gcv_web_detection.WebDetection, - ) - error = proto.Field( - proto.MESSAGE, - number=9, - message=status_pb2.Status, - ) - - -class BatchAnnotateImagesRequest(proto.Message): - r"""Multiple image annotation requests are batched into a single - service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - - -class BatchAnnotateImagesResponse(proto.Message): - r"""Response to a batch image annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p1beta1.types.AnnotateImageResponse]): - Individual responses to image annotation - requests within the batch. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageResponse', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py deleted file mode 100644 index 8b571866..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/text_annotation.py +++ /dev/null @@ -1,378 +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.vision_v1p1beta1.types import geometry - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p1beta1', - manifest={ - 'TextAnnotation', - 'Page', - 'Block', - 'Paragraph', - 'Word', - 'Symbol', - }, -) - - -class TextAnnotation(proto.Message): - r"""TextAnnotation contains a structured representation of OCR extracted - text. The hierarchy of an OCR extracted text structure is like this: - TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each - structural component, starting from Page, may further have their own - properties. Properties describe detected languages, breaks etc.. - Please refer to the - [TextAnnotation.TextProperty][google.cloud.vision.v1p1beta1.TextAnnotation.TextProperty] - message definition below for more detail. - - Attributes: - pages (Sequence[google.cloud.vision_v1p1beta1.types.Page]): - List of pages detected by OCR. - text (str): - UTF-8 text detected on the pages. - """ - - 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, - ) - - class DetectedBreak(proto.Message): - r"""Detected start or end of a structural component. - - Attributes: - type_ (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak.BreakType): - Detected break type. - is_prefix (bool): - True if break prepends the element. - """ - class BreakType(proto.Enum): - r"""Enum to denote the type of break found. New line, space etc.""" - UNKNOWN = 0 - SPACE = 1 - SURE_SPACE = 2 - EOL_SURE_SPACE = 3 - HYPHEN = 4 - LINE_BREAK = 5 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='TextAnnotation.DetectedBreak.BreakType', - ) - is_prefix = proto.Field( - proto.BOOL, - number=2, - ) - - class TextProperty(proto.Message): - r"""Additional information detected on the structural component. - - Attributes: - detected_languages (Sequence[google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedLanguage]): - A list of detected languages together with - confidence. - detected_break (google.cloud.vision_v1p1beta1.types.TextAnnotation.DetectedBreak): - Detected start or end of a text segment. - """ - - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='TextAnnotation.DetectedLanguage', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='TextAnnotation.DetectedBreak', - ) - - pages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Page', - ) - text = proto.Field( - proto.STRING, - number=2, - ) - - -class Page(proto.Message): - r"""Detected page from OCR. - - Attributes: - property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): - Additional information detected on the page. - width (int): - Page width in pixels. - height (int): - Page height in pixels. - blocks (Sequence[google.cloud.vision_v1p1beta1.types.Block]): - List of blocks of text, images etc on this - page. - confidence (float): - Confidence of the OCR results on the page. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - width = proto.Field( - proto.INT32, - number=2, - ) - height = proto.Field( - proto.INT32, - number=3, - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Block', - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Block(proto.Message): - r"""Logical element on the page. - - Attributes: - property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - block. - bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The bounding box for the block. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - paragraphs (Sequence[google.cloud.vision_v1p1beta1.types.Paragraph]): - List of paragraphs in this block (if this - blocks is of type text). - block_type (google.cloud.vision_v1p1beta1.types.Block.BlockType): - Detected block type (text, image etc) for - this block. - confidence (float): - Confidence of the OCR results on the block. Range [0, 1]. - """ - class BlockType(proto.Enum): - r"""Type of a block (text, image etc) as identified by OCR.""" - UNKNOWN = 0 - TEXT = 1 - TABLE = 2 - PICTURE = 3 - RULER = 4 - BARCODE = 5 - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Paragraph', - ) - block_type = proto.Field( - proto.ENUM, - number=4, - enum=BlockType, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Paragraph(proto.Message): - r"""Structural unit of text representing a number of words in - certain order. - - Attributes: - property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - paragraph. - bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The bounding box for the paragraph. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - words (Sequence[google.cloud.vision_v1p1beta1.types.Word]): - List of words in this paragraph. - confidence (float): - Confidence of the OCR results for the paragraph. Range [0, - 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - words = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Word', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Word(proto.Message): - r"""A word representation. - - Attributes: - property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): - Additional information detected for the word. - bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The bounding box for the word. The vertices are in the order - of top-left, top-right, bottom-right, bottom-left. When a - rotation of the bounding box is detected the rotation is - represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - symbols (Sequence[google.cloud.vision_v1p1beta1.types.Symbol]): - List of symbols in the word. - The order of the symbols follows the natural - reading order. - confidence (float): - Confidence of the OCR results for the word. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - symbols = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Symbol', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Symbol(proto.Message): - r"""A single symbol representation. - - Attributes: - property (google.cloud.vision_v1p1beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - symbol. - bounding_box (google.cloud.vision_v1p1beta1.types.BoundingPoly): - The bounding box for the symbol. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - text (str): - The actual UTF-8 representation of the - symbol. - confidence (float): - Confidence of the OCR results for the symbol. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - text = proto.Field( - proto.STRING, - number=3, - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py b/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py deleted file mode 100644 index aeea2bf9..00000000 --- a/owl-bot-staging/v1p1beta1/google/cloud/vision_v1p1beta1/types/web_detection.py +++ /dev/null @@ -1,199 +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.vision.v1p1beta1', - manifest={ - 'WebDetection', - }, -) - - -class WebDetection(proto.Message): - r"""Relevant information for the image from the Internet. - - Attributes: - web_entities (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebEntity]): - Deduced entities from similar images on the - Internet. - full_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): - Fully matching images from the Internet. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): - Partial matching images from the Internet. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - pages_with_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebPage]): - Web pages containing the matching images from - the Internet. - visually_similar_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): - The visually similar image results. - best_guess_labels (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebLabel]): - Best guess text labels for the request image. - """ - - class WebEntity(proto.Message): - r"""Entity deduced from similar images on the Internet. - - Attributes: - entity_id (str): - Opaque entity ID. - score (float): - Overall relevancy score for the entity. - Not normalized and not comparable across - different image queries. - description (str): - Canonical description of the entity, in - English. - """ - - entity_id = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - - class WebImage(proto.Message): - r"""Metadata for online images. - - Attributes: - url (str): - The result image URL. - score (float): - (Deprecated) Overall relevancy score for the - image. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - - class WebPage(proto.Message): - r"""Metadata for web pages. - - Attributes: - url (str): - The result web page URL. - score (float): - (Deprecated) Overall relevancy score for the - web page. - page_title (str): - Title for the web page, may contain HTML - markups. - full_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): - Fully matching images on the page. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p1beta1.types.WebDetection.WebImage]): - Partial matching images on the page. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - page_title = proto.Field( - proto.STRING, - number=3, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='WebDetection.WebImage', - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='WebDetection.WebImage', - ) - - class WebLabel(proto.Message): - r"""Label to provide extra metadata for the web detection. - - Attributes: - label (str): - Label for extra metadata. - language_code (str): - The BCP-47 language code for ``label``, such as "en-US" or - "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - """ - - label = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - - web_entities = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=WebEntity, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=WebImage, - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=WebImage, - ) - pages_with_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=WebPage, - ) - visually_similar_images = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=WebImage, - ) - best_guess_labels = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=WebLabel, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p1beta1/mypy.ini b/owl-bot-staging/v1p1beta1/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1p1beta1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1p1beta1/noxfile.py b/owl-bot-staging/v1p1beta1/noxfile.py deleted file mode 100644 index e4d4b85e..00000000 --- a/owl-bot-staging/v1p1beta1/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/vision_v1p1beta1/', - '--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/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py b/owl-bot-staging/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py deleted file mode 100644 index 9570c77b..00000000 --- a/owl-bot-staging/v1p1beta1/scripts/fixup_vision_v1p1beta1_keywords.py +++ /dev/null @@ -1,176 +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 visionCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_annotate_images': ('requests', ), - } - - 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: a.keyword.value not 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=visionCallTransformer(), -): - """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 vision 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/v1p1beta1/setup.py b/owl-bot-staging/v1p1beta1/setup.py deleted file mode 100644 index 9d03e702..00000000 --- a/owl-bot-staging/v1p1beta1/setup.py +++ /dev/null @@ -1,54 +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-vision', - 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, < 3.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', - 'Programming Language :: Python :: 3.9', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1p1beta1/tests/__init__.py b/owl-bot-staging/v1p1beta1/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p1beta1/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/v1p1beta1/tests/unit/__init__.py b/owl-bot-staging/v1p1beta1/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p1beta1/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/v1p1beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p1beta1/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p1beta1/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/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__init__.py b/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/__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/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py deleted file mode 100644 index 43b216a7..00000000 --- a/owl-bot-staging/v1p1beta1/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ /dev/null @@ -1,1131 +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 gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1p1beta1.services.image_annotator import ImageAnnotatorAsyncClient -from google.cloud.vision_v1p1beta1.services.image_annotator import ImageAnnotatorClient -from google.cloud.vision_v1p1beta1.services.image_annotator import transports -from google.cloud.vision_v1p1beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1p1beta1.types import image_annotator -from google.oauth2 import service_account -from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ImageAnnotatorGrpcTransport, "grpc"), - (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -def test_image_annotator_client_get_transport_class(): - transport = ImageAnnotatorClient.get_transport_class() - available_transports = [ - transports.ImageAnnotatorGrpcTransport, - ] - assert transport in available_transports - - transport = ImageAnnotatorClient.get_transport_class("grpc") - assert transport == transports.ImageAnnotatorGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - -def test_image_annotator_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ImageAnnotatorClient( - 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, - always_use_jwt_access=True, - ) - - -def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse( - ) - response = client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - -def test_batch_annotate_images_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 = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - client.batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( - )) - response = await client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async_from_dict(): - await test_batch_annotate_images_async(request_type=dict) - - -def test_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -def test_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ImageAnnotatorClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, -]) -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 = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ImageAnnotatorGrpcTransport, - ) - -def test_image_annotator_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_image_annotator_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'batch_annotate_images', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_image_annotator_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.vision_v1p1beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ImageAnnotatorGrpcTransport, grpc_helpers), - (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_image_annotator_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_host_no_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_image_annotator_host_with_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_image_annotator_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcTransport( - 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_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ImageAnnotatorClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ImageAnnotatorClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = ImageAnnotatorClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ImageAnnotatorClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ImageAnnotatorClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ImageAnnotatorClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = ImageAnnotatorClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ImageAnnotatorClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ImageAnnotatorClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - transport_class = ImageAnnotatorClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1p2beta1/.coveragerc b/owl-bot-staging/v1p2beta1/.coveragerc deleted file mode 100644 index 75747063..00000000 --- a/owl-bot-staging/v1p2beta1/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/vision/__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/v1p2beta1/MANIFEST.in b/owl-bot-staging/v1p2beta1/MANIFEST.in deleted file mode 100644 index 397ad4e2..00000000 --- a/owl-bot-staging/v1p2beta1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/vision *.py -recursive-include google/cloud/vision_v1p2beta1 *.py diff --git a/owl-bot-staging/v1p2beta1/README.rst b/owl-bot-staging/v1p2beta1/README.rst deleted file mode 100644 index 39f9ca72..00000000 --- a/owl-bot-staging/v1p2beta1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Vision 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 Vision 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/v1p2beta1/docs/conf.py b/owl-bot-staging/v1p2beta1/docs/conf.py deleted file mode 100644 index 6e730bf5..00000000 --- a/owl-bot-staging/v1p2beta1/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-vision 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-vision" -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-vision-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-vision.tex", - u"google-cloud-vision 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-vision", - u"Google Cloud Vision 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-vision", - u"google-cloud-vision Documentation", - author, - "google-cloud-vision", - "GAPIC library for Google Cloud Vision 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/v1p2beta1/docs/index.rst b/owl-bot-staging/v1p2beta1/docs/index.rst deleted file mode 100644 index d7cb733f..00000000 --- a/owl-bot-staging/v1p2beta1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - vision_v1p2beta1/services - vision_v1p2beta1/types diff --git a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst deleted file mode 100644 index d05fd549..00000000 --- a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/image_annotator.rst +++ /dev/null @@ -1,6 +0,0 @@ -ImageAnnotator --------------------------------- - -.. automodule:: google.cloud.vision_v1p2beta1.services.image_annotator - :members: - :inherited-members: diff --git a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst deleted file mode 100644 index 2272ceb5..00000000 --- a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Vision v1p2beta1 API -============================================== -.. toctree:: - :maxdepth: 2 - - image_annotator diff --git a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst b/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst deleted file mode 100644 index 33ab32e0..00000000 --- a/owl-bot-staging/v1p2beta1/docs/vision_v1p2beta1/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Vision v1p2beta1 API -=========================================== - -.. automodule:: google.cloud.vision_v1p2beta1.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py deleted file mode 100644 index 71d258f3..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision/__init__.py +++ /dev/null @@ -1,113 +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.vision_v1p2beta1.services.image_annotator.client import ImageAnnotatorClient -from google.cloud.vision_v1p2beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient - -from google.cloud.vision_v1p2beta1.types.geometry import BoundingPoly -from google.cloud.vision_v1p2beta1.types.geometry import NormalizedVertex -from google.cloud.vision_v1p2beta1.types.geometry import Position -from google.cloud.vision_v1p2beta1.types.geometry import Vertex -from google.cloud.vision_v1p2beta1.types.image_annotator import AnnotateFileResponse -from google.cloud.vision_v1p2beta1.types.image_annotator import AnnotateImageRequest -from google.cloud.vision_v1p2beta1.types.image_annotator import AnnotateImageResponse -from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncAnnotateFileRequest -from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncAnnotateFileResponse -from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncBatchAnnotateFilesRequest -from google.cloud.vision_v1p2beta1.types.image_annotator import AsyncBatchAnnotateFilesResponse -from google.cloud.vision_v1p2beta1.types.image_annotator import BatchAnnotateImagesRequest -from google.cloud.vision_v1p2beta1.types.image_annotator import BatchAnnotateImagesResponse -from google.cloud.vision_v1p2beta1.types.image_annotator import ColorInfo -from google.cloud.vision_v1p2beta1.types.image_annotator import CropHint -from google.cloud.vision_v1p2beta1.types.image_annotator import CropHintsAnnotation -from google.cloud.vision_v1p2beta1.types.image_annotator import CropHintsParams -from google.cloud.vision_v1p2beta1.types.image_annotator import DominantColorsAnnotation -from google.cloud.vision_v1p2beta1.types.image_annotator import EntityAnnotation -from google.cloud.vision_v1p2beta1.types.image_annotator import FaceAnnotation -from google.cloud.vision_v1p2beta1.types.image_annotator import Feature -from google.cloud.vision_v1p2beta1.types.image_annotator import GcsDestination -from google.cloud.vision_v1p2beta1.types.image_annotator import GcsSource -from google.cloud.vision_v1p2beta1.types.image_annotator import Image -from google.cloud.vision_v1p2beta1.types.image_annotator import ImageAnnotationContext -from google.cloud.vision_v1p2beta1.types.image_annotator import ImageContext -from google.cloud.vision_v1p2beta1.types.image_annotator import ImageProperties -from google.cloud.vision_v1p2beta1.types.image_annotator import ImageSource -from google.cloud.vision_v1p2beta1.types.image_annotator import InputConfig -from google.cloud.vision_v1p2beta1.types.image_annotator import LatLongRect -from google.cloud.vision_v1p2beta1.types.image_annotator import LocationInfo -from google.cloud.vision_v1p2beta1.types.image_annotator import OperationMetadata -from google.cloud.vision_v1p2beta1.types.image_annotator import OutputConfig -from google.cloud.vision_v1p2beta1.types.image_annotator import Property -from google.cloud.vision_v1p2beta1.types.image_annotator import SafeSearchAnnotation -from google.cloud.vision_v1p2beta1.types.image_annotator import TextDetectionParams -from google.cloud.vision_v1p2beta1.types.image_annotator import WebDetectionParams -from google.cloud.vision_v1p2beta1.types.image_annotator import Likelihood -from google.cloud.vision_v1p2beta1.types.text_annotation import Block -from google.cloud.vision_v1p2beta1.types.text_annotation import Page -from google.cloud.vision_v1p2beta1.types.text_annotation import Paragraph -from google.cloud.vision_v1p2beta1.types.text_annotation import Symbol -from google.cloud.vision_v1p2beta1.types.text_annotation import TextAnnotation -from google.cloud.vision_v1p2beta1.types.text_annotation import Word -from google.cloud.vision_v1p2beta1.types.web_detection import WebDetection - -__all__ = ('ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', - 'BoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py deleted file mode 100644 index 76642da0..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/__init__.py +++ /dev/null @@ -1,114 +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.image_annotator import ImageAnnotatorClient -from .services.image_annotator import ImageAnnotatorAsyncClient - -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Position -from .types.geometry import Vertex -from .types.image_annotator import AnnotateFileResponse -from .types.image_annotator import AnnotateImageRequest -from .types.image_annotator import AnnotateImageResponse -from .types.image_annotator import AsyncAnnotateFileRequest -from .types.image_annotator import AsyncAnnotateFileResponse -from .types.image_annotator import AsyncBatchAnnotateFilesRequest -from .types.image_annotator import AsyncBatchAnnotateFilesResponse -from .types.image_annotator import BatchAnnotateImagesRequest -from .types.image_annotator import BatchAnnotateImagesResponse -from .types.image_annotator import ColorInfo -from .types.image_annotator import CropHint -from .types.image_annotator import CropHintsAnnotation -from .types.image_annotator import CropHintsParams -from .types.image_annotator import DominantColorsAnnotation -from .types.image_annotator import EntityAnnotation -from .types.image_annotator import FaceAnnotation -from .types.image_annotator import Feature -from .types.image_annotator import GcsDestination -from .types.image_annotator import GcsSource -from .types.image_annotator import Image -from .types.image_annotator import ImageAnnotationContext -from .types.image_annotator import ImageContext -from .types.image_annotator import ImageProperties -from .types.image_annotator import ImageSource -from .types.image_annotator import InputConfig -from .types.image_annotator import LatLongRect -from .types.image_annotator import LocationInfo -from .types.image_annotator import OperationMetadata -from .types.image_annotator import OutputConfig -from .types.image_annotator import Property -from .types.image_annotator import SafeSearchAnnotation -from .types.image_annotator import TextDetectionParams -from .types.image_annotator import WebDetectionParams -from .types.image_annotator import Likelihood -from .types.text_annotation import Block -from .types.text_annotation import Page -from .types.text_annotation import Paragraph -from .types.text_annotation import Symbol -from .types.text_annotation import TextAnnotation -from .types.text_annotation import Word -from .types.web_detection import WebDetection - -__all__ = ( - 'ImageAnnotatorAsyncClient', -'AnnotateFileResponse', -'AnnotateImageRequest', -'AnnotateImageResponse', -'AsyncAnnotateFileRequest', -'AsyncAnnotateFileResponse', -'AsyncBatchAnnotateFilesRequest', -'AsyncBatchAnnotateFilesResponse', -'BatchAnnotateImagesRequest', -'BatchAnnotateImagesResponse', -'Block', -'BoundingPoly', -'ColorInfo', -'CropHint', -'CropHintsAnnotation', -'CropHintsParams', -'DominantColorsAnnotation', -'EntityAnnotation', -'FaceAnnotation', -'Feature', -'GcsDestination', -'GcsSource', -'Image', -'ImageAnnotationContext', -'ImageAnnotatorClient', -'ImageContext', -'ImageProperties', -'ImageSource', -'InputConfig', -'LatLongRect', -'Likelihood', -'LocationInfo', -'NormalizedVertex', -'OperationMetadata', -'OutputConfig', -'Page', -'Paragraph', -'Position', -'Property', -'SafeSearchAnnotation', -'Symbol', -'TextAnnotation', -'TextDetectionParams', -'Vertex', -'WebDetection', -'WebDetectionParams', -'Word', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/gapic_metadata.json b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/gapic_metadata.json deleted file mode 100644 index 3e166a99..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/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.vision_v1p2beta1", - "protoPackage": "google.cloud.vision.v1p2beta1", - "schema": "1.0", - "services": { - "ImageAnnotator": { - "clients": { - "grpc": { - "libraryClient": "ImageAnnotatorClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ImageAnnotatorAsyncClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/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/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__init__.py deleted file mode 100644 index 3cbfa2fa..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/__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 ImageAnnotatorClient -from .async_client import ImageAnnotatorAsyncClient - -__all__ = ( - 'ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py deleted file mode 100644 index 0ab7254b..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/async_client.py +++ /dev/null @@ -1,334 +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.vision_v1p2beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport -from .client import ImageAnnotatorClient - - -class ImageAnnotatorAsyncClient: - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - _client: ImageAnnotatorClient - - DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT - - common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) - parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) - common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) - parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) - common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) - parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) - common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) - parse_common_location_path = staticmethod(ImageAnnotatorClient.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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def batch_annotate_images(self, - request: image_annotator.BatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (:class:`google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest`): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]`): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1p2beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def async_batch_annotate_files(self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Run async image detection and annotation for a list of generic - files (e.g. PDF) which may contain multiple pages and multiple - images per page. Progress and results can be retrieved through - the ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (:class:`google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest`): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]`): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1p2beta1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorAsyncClient", -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py deleted file mode 100644 index 9a55ea78..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/client.py +++ /dev/null @@ -1,508 +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 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.vision_v1p2beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ImageAnnotatorGrpcTransport -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -class ImageAnnotatorClientMeta(type): - """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] - _transport_registry["grpc"] = ImageAnnotatorGrpcTransport - _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ImageAnnotatorTransport]: - """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - @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 = "vision.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: - ImageAnnotatorClient: 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: - ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: 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, ImageAnnotatorTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): - # transport is a ImageAnnotatorTransport 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, - always_use_jwt_access=True, - ) - - def batch_annotate_images(self, - request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (Union[google.cloud.vision_v1p2beta1.types.BatchAnnotateImagesRequest, dict]): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1p2beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 image_annotator.BatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): - request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def async_batch_annotate_files(self, - request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Run async image detection and annotation for a list of generic - files (e.g. PDF) which may contain multiple pages and multiple - images per page. Progress and results can be retrieved through - the ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (Union[google.cloud.vision_v1p2beta1.types.AsyncBatchAnnotateFilesRequest, dict]): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1p2beta1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 image_annotator.AsyncBatchAnnotateFilesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): - request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorClient", -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/__init__.py deleted file mode 100644 index 94f01250..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/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 ImageAnnotatorTransport -from .grpc import ImageAnnotatorGrpcTransport -from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] -_transport_registry['grpc'] = ImageAnnotatorGrpcTransport -_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport - -__all__ = ( - 'ImageAnnotatorTransport', - 'ImageAnnotatorGrpcTransport', - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py deleted file mode 100644 index 6a6810f7..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/base.py +++ /dev/null @@ -1,213 +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.vision_v1p2beta1.types import image_annotator -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-vision', - ).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 ImageAnnotatorTransport(abc.ABC): - """Abstract transport class for ImageAnnotator.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( - self.batch_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.async_batch_annotate_files: gapic_v1.method.wrap_method( - self.async_batch_annotate_files, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Union[ - image_annotator.BatchAnnotateImagesResponse, - Awaitable[image_annotator.BatchAnnotateImagesResponse] - ]]: - raise NotImplementedError() - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ImageAnnotatorTransport', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.py deleted file mode 100644 index 48661c3f..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc.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 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.vision_v1p2beta1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO - - -class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): - """gRPC backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - image_annotator.BatchAnnotateImagesResponse]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - ~.BatchAnnotateImagesResponse]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p2beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - operations_pb2.Operation]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run async image detection and annotation for a list of generic - files (e.g. PDF) which may contain multiple pages and multiple - images per page. Progress and results can be retrieved through - the ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - ~.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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ImageAnnotatorGrpcTransport', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py deleted file mode 100644 index 4276ae50..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/services/image_annotator/transports/grpc_asyncio.py +++ /dev/null @@ -1,314 +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.vision_v1p2beta1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .grpc import ImageAnnotatorGrpcTransport - - -class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): - """gRPC AsyncIO backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Awaitable[image_annotator.BatchAnnotateImagesResponse]]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - Awaitable[~.BatchAnnotateImagesResponse]]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p2beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run async image detection and annotation for a list of generic - files (e.g. PDF) which may contain multiple pages and multiple - images per page. Progress and results can be retrieved through - the ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - 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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py deleted file mode 100644 index 749f2495..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/__init__.py +++ /dev/null @@ -1,116 +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 .geometry import ( - BoundingPoly, - NormalizedVertex, - Position, - Vertex, -) -from .image_annotator import ( - AnnotateFileResponse, - AnnotateImageRequest, - AnnotateImageResponse, - AsyncAnnotateFileRequest, - AsyncAnnotateFileResponse, - AsyncBatchAnnotateFilesRequest, - AsyncBatchAnnotateFilesResponse, - BatchAnnotateImagesRequest, - BatchAnnotateImagesResponse, - ColorInfo, - CropHint, - CropHintsAnnotation, - CropHintsParams, - DominantColorsAnnotation, - EntityAnnotation, - FaceAnnotation, - Feature, - GcsDestination, - GcsSource, - Image, - ImageAnnotationContext, - ImageContext, - ImageProperties, - ImageSource, - InputConfig, - LatLongRect, - LocationInfo, - OperationMetadata, - OutputConfig, - Property, - SafeSearchAnnotation, - TextDetectionParams, - WebDetectionParams, - Likelihood, -) -from .text_annotation import ( - Block, - Page, - Paragraph, - Symbol, - TextAnnotation, - Word, -) -from .web_detection import ( - WebDetection, -) - -__all__ = ( - 'BoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py deleted file mode 100644 index 03b876c4..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/geometry.py +++ /dev/null @@ -1,125 +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.vision.v1p2beta1', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - 'Position', - }, -) - - -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.vision_v1p2beta1.types.Vertex]): - The bounding polygon vertices. - normalized_vertices (Sequence[google.cloud.vision_v1p2beta1.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', - ) - - -class Position(proto.Message): - r"""A 3D position in the image, used primarily for Face detection - landmarks. A valid Position must have both x and y coordinates. - The position coordinates are in the same scale as the original - image. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate. - z (float): - Z coordinate (or depth). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - z = proto.Field( - proto.FLOAT, - number=3, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py deleted file mode 100644 index 6af9e3ed..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/image_annotator.py +++ /dev/null @@ -1,1256 +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.vision_v1p2beta1.types import geometry -from google.cloud.vision_v1p2beta1.types import text_annotation -from google.cloud.vision_v1p2beta1.types import web_detection as gcv_web_detection -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 latlng_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p2beta1', - manifest={ - 'Likelihood', - 'Feature', - 'ImageSource', - 'Image', - 'FaceAnnotation', - 'LocationInfo', - 'Property', - 'EntityAnnotation', - 'SafeSearchAnnotation', - 'LatLongRect', - 'ColorInfo', - 'DominantColorsAnnotation', - 'ImageProperties', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'WebDetectionParams', - 'TextDetectionParams', - 'ImageContext', - 'AnnotateImageRequest', - 'ImageAnnotationContext', - 'AnnotateImageResponse', - 'AnnotateFileResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'InputConfig', - 'OutputConfig', - 'GcsSource', - 'GcsDestination', - 'OperationMetadata', - }, -) - - -class Likelihood(proto.Enum): - r"""A bucketized representation of likelihood, which is intended - to give clients highly stable results across model upgrades. - """ - UNKNOWN = 0 - VERY_UNLIKELY = 1 - UNLIKELY = 2 - POSSIBLE = 3 - LIKELY = 4 - VERY_LIKELY = 5 - - -class Feature(proto.Message): - r"""The type of Google Cloud Vision API detection to perform, and the - maximum number of results to return for that type. Multiple - ``Feature`` objects can be specified in the ``features`` list. - - Attributes: - type_ (google.cloud.vision_v1p2beta1.types.Feature.Type): - The feature type. - max_results (int): - Maximum number of results of this type. Does not apply to - ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or - ``CROP_HINTS``. - model (str): - Model to use for the feature. - Supported values: "builtin/stable" (the default - if unset) and "builtin/latest". - """ - class Type(proto.Enum): - r"""Type of Google Cloud Vision API feature to be extracted.""" - TYPE_UNSPECIFIED = 0 - FACE_DETECTION = 1 - LANDMARK_DETECTION = 2 - LOGO_DETECTION = 3 - LABEL_DETECTION = 4 - TEXT_DETECTION = 5 - DOCUMENT_TEXT_DETECTION = 11 - SAFE_SEARCH_DETECTION = 6 - IMAGE_PROPERTIES = 7 - CROP_HINTS = 9 - WEB_DETECTION = 10 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum=Type, - ) - max_results = proto.Field( - proto.INT32, - number=2, - ) - model = proto.Field( - proto.STRING, - number=3, - ) - - -class ImageSource(proto.Message): - r"""External image source (Google Cloud Storage or web URL image - location). - - Attributes: - gcs_image_uri (str): - **Use ``image_uri`` instead.** - - The 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. - image_uri (str): - The URI of the source image. Can be either: - - 1. A 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. - - 2. A publicly-accessible image HTTP/HTTPS URL. When fetching - images from HTTP/HTTPS URLs, Google cannot guarantee that - the request will be completed. Your request may fail if - the specified host denies the request (e.g. due to - request throttling or DOS prevention), or if Google - throttles requests to the site for abuse prevention. You - should not depend on externally-hosted images for - production applications. - - When both ``gcs_image_uri`` and ``image_uri`` are specified, - ``image_uri`` takes precedence. - """ - - gcs_image_uri = proto.Field( - proto.STRING, - number=1, - ) - image_uri = proto.Field( - proto.STRING, - number=2, - ) - - -class Image(proto.Message): - r"""Client image to perform Google Cloud Vision API tasks over. - - Attributes: - content (bytes): - Image content, represented as a stream of bytes. Note: As - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - source (google.cloud.vision_v1p2beta1.types.ImageSource): - Google Cloud Storage image location, or publicly-accessible - image URL. If both ``content`` and ``source`` are provided - for an image, ``content`` takes precedence and is used to - perform the image annotation request. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - source = proto.Field( - proto.MESSAGE, - number=2, - message='ImageSource', - ) - - -class FaceAnnotation(proto.Message): - r"""A face annotation object contains the results of face - detection. - - Attributes: - bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The bounding polygon around the face. The coordinates of the - bounding box are in the original image's scale, as returned - in ``ImageParams``. The bounding box is computed to "frame" - the face in accordance with human expectations. It is based - on the landmarker results. Note that one or more x and/or y - coordinates may not be generated in the ``BoundingPoly`` - (the polygon will be unbounded) if only a partial face - appears in the image to be annotated. - fd_bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The ``fd_bounding_poly`` bounding polygon is tighter than - the ``boundingPoly``, and encloses only the skin part of the - face. Typically, it is used to eliminate the face from any - image analysis that detects the "amount of skin" visible in - an image. It is not based on the landmarker results, only on - the initial face detection, hence the fd (face detection) - prefix. - landmarks (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark]): - Detected face landmarks. - roll_angle (float): - Roll angle, which indicates the amount of - clockwise/anti-clockwise rotation of the face relative to - the image vertical about the axis perpendicular to the face. - Range [-180,180]. - pan_angle (float): - Yaw angle, which indicates the leftward/rightward angle that - the face is pointing relative to the vertical plane - perpendicular to the image. Range [-180,180]. - tilt_angle (float): - Pitch angle, which indicates the upwards/downwards angle - that the face is pointing relative to the image's horizontal - plane. Range [-180,180]. - detection_confidence (float): - Detection confidence. Range [0, 1]. - landmarking_confidence (float): - Face landmarking confidence. Range [0, 1]. - joy_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Joy likelihood. - sorrow_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Sorrow likelihood. - anger_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Anger likelihood. - surprise_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Surprise likelihood. - under_exposed_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Under-exposed likelihood. - blurred_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Blurred likelihood. - headwear_likelihood (google.cloud.vision_v1p2beta1.types.Likelihood): - Headwear likelihood. - """ - - class Landmark(proto.Message): - r"""A face-specific landmark (for example, a face feature). - - Attributes: - type_ (google.cloud.vision_v1p2beta1.types.FaceAnnotation.Landmark.Type): - Face landmark type. - position (google.cloud.vision_v1p2beta1.types.Position): - Face landmark position. - """ - class Type(proto.Enum): - r"""Face landmark (feature) type. Left and right are defined from the - vantage of the viewer of the image without considering mirror - projections typical of photos. So, ``LEFT_EYE``, typically, is the - person's right eye. - """ - UNKNOWN_LANDMARK = 0 - LEFT_EYE = 1 - RIGHT_EYE = 2 - LEFT_OF_LEFT_EYEBROW = 3 - RIGHT_OF_LEFT_EYEBROW = 4 - LEFT_OF_RIGHT_EYEBROW = 5 - RIGHT_OF_RIGHT_EYEBROW = 6 - MIDPOINT_BETWEEN_EYES = 7 - NOSE_TIP = 8 - UPPER_LIP = 9 - LOWER_LIP = 10 - MOUTH_LEFT = 11 - MOUTH_RIGHT = 12 - MOUTH_CENTER = 13 - NOSE_BOTTOM_RIGHT = 14 - NOSE_BOTTOM_LEFT = 15 - NOSE_BOTTOM_CENTER = 16 - LEFT_EYE_TOP_BOUNDARY = 17 - LEFT_EYE_RIGHT_CORNER = 18 - LEFT_EYE_BOTTOM_BOUNDARY = 19 - LEFT_EYE_LEFT_CORNER = 20 - RIGHT_EYE_TOP_BOUNDARY = 21 - RIGHT_EYE_RIGHT_CORNER = 22 - RIGHT_EYE_BOTTOM_BOUNDARY = 23 - RIGHT_EYE_LEFT_CORNER = 24 - LEFT_EYEBROW_UPPER_MIDPOINT = 25 - RIGHT_EYEBROW_UPPER_MIDPOINT = 26 - LEFT_EAR_TRAGION = 27 - RIGHT_EAR_TRAGION = 28 - LEFT_EYE_PUPIL = 29 - RIGHT_EYE_PUPIL = 30 - FOREHEAD_GLABELLA = 31 - CHIN_GNATHION = 32 - CHIN_LEFT_GONION = 33 - CHIN_RIGHT_GONION = 34 - - type_ = proto.Field( - proto.ENUM, - number=3, - enum='FaceAnnotation.Landmark.Type', - ) - position = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.Position, - ) - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - fd_bounding_poly = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - landmarks = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=Landmark, - ) - roll_angle = proto.Field( - proto.FLOAT, - number=4, - ) - pan_angle = proto.Field( - proto.FLOAT, - number=5, - ) - tilt_angle = proto.Field( - proto.FLOAT, - number=6, - ) - detection_confidence = proto.Field( - proto.FLOAT, - number=7, - ) - landmarking_confidence = proto.Field( - proto.FLOAT, - number=8, - ) - joy_likelihood = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - sorrow_likelihood = proto.Field( - proto.ENUM, - number=10, - enum='Likelihood', - ) - anger_likelihood = proto.Field( - proto.ENUM, - number=11, - enum='Likelihood', - ) - surprise_likelihood = proto.Field( - proto.ENUM, - number=12, - enum='Likelihood', - ) - under_exposed_likelihood = proto.Field( - proto.ENUM, - number=13, - enum='Likelihood', - ) - blurred_likelihood = proto.Field( - proto.ENUM, - number=14, - enum='Likelihood', - ) - headwear_likelihood = proto.Field( - proto.ENUM, - number=15, - enum='Likelihood', - ) - - -class LocationInfo(proto.Message): - r"""Detected entity location information. - - Attributes: - lat_lng (google.type.latlng_pb2.LatLng): - lat/long location coordinates. - """ - - lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - - -class Property(proto.Message): - r"""A ``Property`` consists of a user-supplied name/value pair. - - Attributes: - name (str): - Name of the property. - value (str): - Value of the property. - uint64_value (int): - Value of numeric properties. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - uint64_value = proto.Field( - proto.UINT64, - number=3, - ) - - -class EntityAnnotation(proto.Message): - r"""Set of detected entity features. - - Attributes: - mid (str): - Opaque entity ID. Some IDs may be available in `Google - Knowledge Graph Search - API `__. - locale (str): - The language code for the locale in which the entity textual - ``description`` is expressed. - description (str): - Entity textual description, expressed in its ``locale`` - language. - score (float): - Overall score of the result. Range [0, 1]. - confidence (float): - **Deprecated. Use ``score`` instead.** The accuracy of the - entity detection in an image. For example, for an image in - which the "Eiffel Tower" entity is detected, this field - represents the confidence that there is a tower in the query - image. Range [0, 1]. - topicality (float): - The relevancy of the ICA (Image Content Annotation) label to - the image. For example, the relevancy of "tower" is likely - higher to an image containing the detected "Eiffel Tower" - than to an image containing a detected distant towering - building, even though the confidence that there is a tower - in each image may be the same. Range [0, 1]. - bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): - Image region to which this entity belongs. Not produced for - ``LABEL_DETECTION`` features. - locations (Sequence[google.cloud.vision_v1p2beta1.types.LocationInfo]): - The location information for the detected entity. Multiple - ``LocationInfo`` elements can be present because one - location may indicate the location of the scene in the - image, and another location may indicate the location of the - place where the image was taken. Location information is - usually present for landmarks. - properties (Sequence[google.cloud.vision_v1p2beta1.types.Property]): - Some entities may have optional user-supplied ``Property`` - (name/value) fields, such a score or string that qualifies - the entity. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - locale = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - topicality = proto.Field( - proto.FLOAT, - number=6, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=7, - message=geometry.BoundingPoly, - ) - locations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='LocationInfo', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Property', - ) - - -class SafeSearchAnnotation(proto.Message): - r"""Set of features pertaining to the image, computed by computer - vision methods over safe-search verticals (for example, adult, - spoof, medical, violence). - - Attributes: - adult (google.cloud.vision_v1p2beta1.types.Likelihood): - Represents the adult content likelihood for - the image. Adult content may contain elements - such as nudity, pornographic images or cartoons, - or sexual activities. - spoof (google.cloud.vision_v1p2beta1.types.Likelihood): - Spoof likelihood. The likelihood that an - modification was made to the image's canonical - version to make it appear funny or offensive. - medical (google.cloud.vision_v1p2beta1.types.Likelihood): - Likelihood that this is a medical image. - violence (google.cloud.vision_v1p2beta1.types.Likelihood): - Likelihood that this image contains violent - content. - racy (google.cloud.vision_v1p2beta1.types.Likelihood): - Likelihood that the request image contains - racy content. Racy content may include (but is - not limited to) skimpy or sheer clothing, - strategically covered nudity, lewd or - provocative poses, or close-ups of sensitive - body areas. - """ - - adult = proto.Field( - proto.ENUM, - number=1, - enum='Likelihood', - ) - spoof = proto.Field( - proto.ENUM, - number=2, - enum='Likelihood', - ) - medical = proto.Field( - proto.ENUM, - number=3, - enum='Likelihood', - ) - violence = proto.Field( - proto.ENUM, - number=4, - enum='Likelihood', - ) - racy = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - - -class LatLongRect(proto.Message): - r"""Rectangle determined by min and max ``LatLng`` pairs. - - Attributes: - min_lat_lng (google.type.latlng_pb2.LatLng): - Min lat/long pair. - max_lat_lng (google.type.latlng_pb2.LatLng): - Max lat/long pair. - """ - - min_lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - max_lat_lng = proto.Field( - proto.MESSAGE, - number=2, - message=latlng_pb2.LatLng, - ) - - -class ColorInfo(proto.Message): - r"""Color information consists of RGB channels, score, and the - fraction of the image that the color occupies in the image. - - Attributes: - color (google.type.color_pb2.Color): - RGB components of the color. - score (float): - Image-specific score for this color. Value in range [0, 1]. - pixel_fraction (float): - The fraction of pixels the color occupies in the image. - Value in range [0, 1]. - """ - - color = proto.Field( - proto.MESSAGE, - number=1, - message=color_pb2.Color, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - pixel_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class DominantColorsAnnotation(proto.Message): - r"""Set of dominant colors and their corresponding scores. - - Attributes: - colors (Sequence[google.cloud.vision_v1p2beta1.types.ColorInfo]): - RGB color values with their score and pixel - fraction. - """ - - colors = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ColorInfo', - ) - - -class ImageProperties(proto.Message): - r"""Stores image properties, such as dominant colors. - - Attributes: - dominant_colors (google.cloud.vision_v1p2beta1.types.DominantColorsAnnotation): - If present, dominant colors completed - successfully. - """ - - dominant_colors = proto.Field( - proto.MESSAGE, - number=1, - message='DominantColorsAnnotation', - ) - - -class CropHint(proto.Message): - r"""Single crop hint that is used to generate a new crop when - serving an image. - - Attributes: - bounding_poly (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The bounding polygon for the crop region. The coordinates of - the bounding box are in the original image's scale, as - returned in ``ImageParams``. - confidence (float): - Confidence of this being a salient region. Range [0, 1]. - importance_fraction (float): - Fraction of importance of this salient region - with respect to the original image. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - importance_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class CropHintsAnnotation(proto.Message): - r"""Set of crop hints that are used to generate new crops when - serving images. - - Attributes: - crop_hints (Sequence[google.cloud.vision_v1p2beta1.types.CropHint]): - Crop hint results. - """ - - crop_hints = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='CropHint', - ) - - -class CropHintsParams(proto.Message): - r"""Parameters for crop hints annotation request. - - Attributes: - aspect_ratios (Sequence[float]): - Aspect ratios in floats, representing the - ratio of the width to the height of the image. - For example, if the desired aspect ratio is 4/3, - the corresponding float value should be 1.33333. - If not specified, the best possible crop is - returned. The number of provided aspect ratios - is limited to a maximum of 16; any aspect ratios - provided after the 16th are ignored. - """ - - aspect_ratios = proto.RepeatedField( - proto.FLOAT, - number=1, - ) - - -class WebDetectionParams(proto.Message): - r"""Parameters for web detection request. - - Attributes: - include_geo_results (bool): - Whether to include results derived from the - geo information in the image. - """ - - include_geo_results = proto.Field( - proto.BOOL, - number=2, - ) - - -class TextDetectionParams(proto.Message): - r"""Parameters for text detections. This is used to control - TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. - - Attributes: - enable_text_detection_confidence_score (bool): - By default, Cloud Vision API only includes confidence score - for DOCUMENT_TEXT_DETECTION result. Set the flag to true to - include confidence score for TEXT_DETECTION as well. - """ - - enable_text_detection_confidence_score = proto.Field( - proto.BOOL, - number=9, - ) - - -class ImageContext(proto.Message): - r"""Image context and/or feature-specific parameters. - - Attributes: - lat_long_rect (google.cloud.vision_v1p2beta1.types.LatLongRect): - Not used. - language_hints (Sequence[str]): - List of languages to use for TEXT_DETECTION. 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). - Text detection returns an error if one or more of the - specified languages is not one of the `supported - languages `__. - crop_hints_params (google.cloud.vision_v1p2beta1.types.CropHintsParams): - Parameters for crop hints annotation request. - web_detection_params (google.cloud.vision_v1p2beta1.types.WebDetectionParams): - Parameters for web detection. - text_detection_params (google.cloud.vision_v1p2beta1.types.TextDetectionParams): - Parameters for text detection and document - text detection. - """ - - lat_long_rect = proto.Field( - proto.MESSAGE, - number=1, - message='LatLongRect', - ) - language_hints = proto.RepeatedField( - proto.STRING, - number=2, - ) - crop_hints_params = proto.Field( - proto.MESSAGE, - number=4, - message='CropHintsParams', - ) - web_detection_params = proto.Field( - proto.MESSAGE, - number=6, - message='WebDetectionParams', - ) - text_detection_params = proto.Field( - proto.MESSAGE, - number=12, - message='TextDetectionParams', - ) - - -class AnnotateImageRequest(proto.Message): - r"""Request for performing Google Cloud Vision API tasks over a - user-provided image, with user-requested features. - - Attributes: - image (google.cloud.vision_v1p2beta1.types.Image): - The image to be processed. - features (Sequence[google.cloud.vision_v1p2beta1.types.Feature]): - Requested features. - image_context (google.cloud.vision_v1p2beta1.types.ImageContext): - Additional context that may accompany the - image. - """ - - image = proto.Field( - proto.MESSAGE, - number=1, - message='Image', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - - -class ImageAnnotationContext(proto.Message): - r"""If an image was produced from a file (e.g. a PDF), this - message gives information about the source of that image. - - Attributes: - uri (str): - The URI of the file used to produce the - image. - page_number (int): - If the file was a PDF or TIFF, this field - gives the page number within the file used to - produce the image. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - page_number = proto.Field( - proto.INT32, - number=2, - ) - - -class AnnotateImageResponse(proto.Message): - r"""Response to an image annotation request. - - Attributes: - face_annotations (Sequence[google.cloud.vision_v1p2beta1.types.FaceAnnotation]): - If present, face detection has completed - successfully. - landmark_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): - If present, landmark detection has completed - successfully. - logo_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): - If present, logo detection has completed - successfully. - label_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): - If present, label detection has completed - successfully. - text_annotations (Sequence[google.cloud.vision_v1p2beta1.types.EntityAnnotation]): - If present, text (OCR) detection has - completed successfully. - full_text_annotation (google.cloud.vision_v1p2beta1.types.TextAnnotation): - If present, text (OCR) detection or document - (OCR) text detection has completed successfully. - This annotation provides the structural - hierarchy for the OCR detected text. - safe_search_annotation (google.cloud.vision_v1p2beta1.types.SafeSearchAnnotation): - If present, safe-search annotation has - completed successfully. - image_properties_annotation (google.cloud.vision_v1p2beta1.types.ImageProperties): - If present, image properties were extracted - successfully. - crop_hints_annotation (google.cloud.vision_v1p2beta1.types.CropHintsAnnotation): - If present, crop hints have completed - successfully. - web_detection (google.cloud.vision_v1p2beta1.types.WebDetection): - If present, web detection has completed - successfully. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the operation. Note - that filled-in image annotations are guaranteed to be - correct, even when ``error`` is set. - context (google.cloud.vision_v1p2beta1.types.ImageAnnotationContext): - If present, contextual information is needed - to understand where this image comes from. - """ - - face_annotations = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='FaceAnnotation', - ) - landmark_annotations = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='EntityAnnotation', - ) - logo_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='EntityAnnotation', - ) - label_annotations = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='EntityAnnotation', - ) - text_annotations = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='EntityAnnotation', - ) - full_text_annotation = proto.Field( - proto.MESSAGE, - number=12, - message=text_annotation.TextAnnotation, - ) - safe_search_annotation = proto.Field( - proto.MESSAGE, - number=6, - message='SafeSearchAnnotation', - ) - image_properties_annotation = proto.Field( - proto.MESSAGE, - number=8, - message='ImageProperties', - ) - crop_hints_annotation = proto.Field( - proto.MESSAGE, - number=11, - message='CropHintsAnnotation', - ) - web_detection = proto.Field( - proto.MESSAGE, - number=13, - message=gcv_web_detection.WebDetection, - ) - error = proto.Field( - proto.MESSAGE, - number=9, - message=status_pb2.Status, - ) - context = proto.Field( - proto.MESSAGE, - number=21, - message='ImageAnnotationContext', - ) - - -class AnnotateFileResponse(proto.Message): - r"""Response to a single file annotation request. A file may - contain one or more images, which individually have their own - responses. - - Attributes: - input_config (google.cloud.vision_v1p2beta1.types.InputConfig): - Information about the file for which this - response is generated. - responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): - Individual responses to images found within - the file. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - responses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AnnotateImageResponse', - ) - - -class BatchAnnotateImagesRequest(proto.Message): - r"""Multiple image annotation requests are batched into a single - service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - - -class BatchAnnotateImagesResponse(proto.Message): - r"""Response to a batch image annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p2beta1.types.AnnotateImageResponse]): - Individual responses to image annotation - requests within the batch. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageResponse', - ) - - -class AsyncAnnotateFileRequest(proto.Message): - r"""An offline file annotation request. - - Attributes: - input_config (google.cloud.vision_v1p2beta1.types.InputConfig): - Required. Information about the input file. - features (Sequence[google.cloud.vision_v1p2beta1.types.Feature]): - Required. Requested features. - image_context (google.cloud.vision_v1p2beta1.types.ImageContext): - Additional context that may accompany the - image(s) in the file. - output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): - Required. The desired output location and - metadata (e.g. format). - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - output_config = proto.Field( - proto.MESSAGE, - number=4, - message='OutputConfig', - ) - - -class AsyncAnnotateFileResponse(proto.Message): - r"""The response for a single offline file annotation request. - - Attributes: - output_config (google.cloud.vision_v1p2beta1.types.OutputConfig): - The output location and metadata from - AsyncAnnotateFileRequest. - """ - - output_config = proto.Field( - proto.MESSAGE, - number=1, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateFilesRequest(proto.Message): - r"""Multiple async file annotation requests are batched into a - single service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileRequest]): - Required. Individual async file annotation - requests for this batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileRequest', - ) - - -class AsyncBatchAnnotateFilesResponse(proto.Message): - r"""Response to an async batch file annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p2beta1.types.AsyncAnnotateFileResponse]): - The list of file annotation responses, one - for each request in - AsyncBatchAnnotateFilesRequest. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileResponse', - ) - - -class InputConfig(proto.Message): - r"""The desired input location and metadata. - - Attributes: - gcs_source (google.cloud.vision_v1p2beta1.types.GcsSource): - The Google Cloud Storage location to read the - input from. - mime_type (str): - The type of the file. Currently only - "application/pdf" and "image/tiff" are - supported. Wildcards are not supported. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - message='GcsSource', - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class OutputConfig(proto.Message): - r"""The desired output location and metadata. - - Attributes: - gcs_destination (google.cloud.vision_v1p2beta1.types.GcsDestination): - The Google Cloud Storage location to write - the output(s) to. - batch_size (int): - The max number of response protos to put into each output - JSON file on GCS. The valid range is [1, 100]. If not - specified, the default value is 20. - - For example, for one pdf file with 100 pages, 100 response - protos will be generated. If ``batch_size`` = 20, then 5 - json files each containing 20 response protos will be - written under the prefix ``gcs_destination``.\ ``uri``. - - Currently, batch_size only applies to GcsDestination, with - potential future support for other output configurations. - """ - - gcs_destination = proto.Field( - proto.MESSAGE, - number=1, - message='GcsDestination', - ) - batch_size = proto.Field( - proto.INT32, - number=2, - ) - - -class GcsSource(proto.Message): - r"""The Google Cloud Storage location where the input will be - read from. - - Attributes: - uri (str): - Google Cloud Storage URI for the input file. - This must only be a GCS object. Wildcards are - not currently supported. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class GcsDestination(proto.Message): - r"""The Google Cloud Storage location where the output will be - written to. - - Attributes: - uri (str): - Google Cloud Storage URI where the results will be stored. - Results will be in JSON format and preceded by its - corresponding input URI. This field can either represent a - single file, or a prefix for multiple outputs. Prefixes must - end in a ``/``. - - Examples: - - - File: gs://bucket-name/filename.json - - Prefix: gs://bucket-name/prefix/here/ - - File: gs://bucket-name/prefix/here - - If multiple outputs, each response is still - AnnotateFileResponse, each of which contains some subset of - the full list of AnnotateImageResponse. Multiple outputs can - happen if, for example, the output JSON is too large and - overflows into multiple sharded files. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class OperationMetadata(proto.Message): - r"""Contains metadata for the BatchAnnotateImages operation. - - Attributes: - state (google.cloud.vision_v1p2beta1.types.OperationMetadata.State): - Current state of the batch operation. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was received. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the operation result was last - updated. - """ - class State(proto.Enum): - r"""Batch operation states.""" - STATE_UNSPECIFIED = 0 - CREATED = 1 - RUNNING = 2 - DONE = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - create_time = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=6, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py deleted file mode 100644 index 96da0434..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/text_annotation.py +++ /dev/null @@ -1,393 +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.vision_v1p2beta1.types import geometry - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p2beta1', - manifest={ - 'TextAnnotation', - 'Page', - 'Block', - 'Paragraph', - 'Word', - 'Symbol', - }, -) - - -class TextAnnotation(proto.Message): - r"""TextAnnotation contains a structured representation of OCR extracted - text. The hierarchy of an OCR extracted text structure is like this: - TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each - structural component, starting from Page, may further have their own - properties. Properties describe detected languages, breaks etc.. - Please refer to the - [TextAnnotation.TextProperty][google.cloud.vision.v1p2beta1.TextAnnotation.TextProperty] - message definition below for more detail. - - Attributes: - pages (Sequence[google.cloud.vision_v1p2beta1.types.Page]): - List of pages detected by OCR. - text (str): - UTF-8 text detected on the pages. - """ - - 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, - ) - - class DetectedBreak(proto.Message): - r"""Detected start or end of a structural component. - - Attributes: - type_ (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak.BreakType): - Detected break type. - is_prefix (bool): - True if break prepends the element. - """ - class BreakType(proto.Enum): - r"""Enum to denote the type of break found. New line, space etc.""" - UNKNOWN = 0 - SPACE = 1 - SURE_SPACE = 2 - EOL_SURE_SPACE = 3 - HYPHEN = 4 - LINE_BREAK = 5 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='TextAnnotation.DetectedBreak.BreakType', - ) - is_prefix = proto.Field( - proto.BOOL, - number=2, - ) - - class TextProperty(proto.Message): - r"""Additional information detected on the structural component. - - Attributes: - detected_languages (Sequence[google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedLanguage]): - A list of detected languages together with - confidence. - detected_break (google.cloud.vision_v1p2beta1.types.TextAnnotation.DetectedBreak): - Detected start or end of a text segment. - """ - - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='TextAnnotation.DetectedLanguage', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='TextAnnotation.DetectedBreak', - ) - - pages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Page', - ) - text = proto.Field( - proto.STRING, - number=2, - ) - - -class Page(proto.Message): - r"""Detected page from OCR. - - Attributes: - property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): - Additional information detected on the page. - width (int): - Page width. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - height (int): - Page height. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - blocks (Sequence[google.cloud.vision_v1p2beta1.types.Block]): - List of blocks of text, images etc on this - page. - confidence (float): - Confidence of the OCR results on the page. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - width = proto.Field( - proto.INT32, - number=2, - ) - height = proto.Field( - proto.INT32, - number=3, - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Block', - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Block(proto.Message): - r"""Logical element on the page. - - Attributes: - property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - block. - bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The bounding box for the block. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: - - :: - - 0----1 - | | - 3----2 - - - when it's rotated 180 degrees around the top-left corner - it becomes: - - :: - - 2----3 - | | - 1----0 - - and the vertice order will still be (0, 1, 2, 3). - paragraphs (Sequence[google.cloud.vision_v1p2beta1.types.Paragraph]): - List of paragraphs in this block (if this - blocks is of type text). - block_type (google.cloud.vision_v1p2beta1.types.Block.BlockType): - Detected block type (text, image etc) for - this block. - confidence (float): - Confidence of the OCR results on the block. Range [0, 1]. - """ - class BlockType(proto.Enum): - r"""Type of a block (text, image etc) as identified by OCR.""" - UNKNOWN = 0 - TEXT = 1 - TABLE = 2 - PICTURE = 3 - RULER = 4 - BARCODE = 5 - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Paragraph', - ) - block_type = proto.Field( - proto.ENUM, - number=4, - enum=BlockType, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Paragraph(proto.Message): - r"""Structural unit of text representing a number of words in - certain order. - - Attributes: - property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - paragraph. - bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The bounding box for the paragraph. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - words (Sequence[google.cloud.vision_v1p2beta1.types.Word]): - List of words in this paragraph. - confidence (float): - Confidence of the OCR results for the paragraph. Range [0, - 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - words = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Word', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Word(proto.Message): - r"""A word representation. - - Attributes: - property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): - Additional information detected for the word. - bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The bounding box for the word. The vertices are in the order - of top-left, top-right, bottom-right, bottom-left. When a - rotation of the bounding box is detected the rotation is - represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - symbols (Sequence[google.cloud.vision_v1p2beta1.types.Symbol]): - List of symbols in the word. - The order of the symbols follows the natural - reading order. - confidence (float): - Confidence of the OCR results for the word. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - symbols = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Symbol', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Symbol(proto.Message): - r"""A single symbol representation. - - Attributes: - property (google.cloud.vision_v1p2beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - symbol. - bounding_box (google.cloud.vision_v1p2beta1.types.BoundingPoly): - The bounding box for the symbol. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - text (str): - The actual UTF-8 representation of the - symbol. - confidence (float): - Confidence of the OCR results for the symbol. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - text = proto.Field( - proto.STRING, - number=3, - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py b/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py deleted file mode 100644 index 0f5fbefd..00000000 --- a/owl-bot-staging/v1p2beta1/google/cloud/vision_v1p2beta1/types/web_detection.py +++ /dev/null @@ -1,199 +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.vision.v1p2beta1', - manifest={ - 'WebDetection', - }, -) - - -class WebDetection(proto.Message): - r"""Relevant information for the image from the Internet. - - Attributes: - web_entities (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebEntity]): - Deduced entities from similar images on the - Internet. - full_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): - Fully matching images from the Internet. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): - Partial matching images from the Internet. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - pages_with_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebPage]): - Web pages containing the matching images from - the Internet. - visually_similar_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): - The visually similar image results. - best_guess_labels (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebLabel]): - Best guess text labels for the request image. - """ - - class WebEntity(proto.Message): - r"""Entity deduced from similar images on the Internet. - - Attributes: - entity_id (str): - Opaque entity ID. - score (float): - Overall relevancy score for the entity. - Not normalized and not comparable across - different image queries. - description (str): - Canonical description of the entity, in - English. - """ - - entity_id = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - - class WebImage(proto.Message): - r"""Metadata for online images. - - Attributes: - url (str): - The result image URL. - score (float): - (Deprecated) Overall relevancy score for the - image. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - - class WebPage(proto.Message): - r"""Metadata for web pages. - - Attributes: - url (str): - The result web page URL. - score (float): - (Deprecated) Overall relevancy score for the - web page. - page_title (str): - Title for the web page, may contain HTML - markups. - full_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): - Fully matching images on the page. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p2beta1.types.WebDetection.WebImage]): - Partial matching images on the page. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - page_title = proto.Field( - proto.STRING, - number=3, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='WebDetection.WebImage', - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='WebDetection.WebImage', - ) - - class WebLabel(proto.Message): - r"""Label to provide extra metadata for the web detection. - - Attributes: - label (str): - Label for extra metadata. - language_code (str): - The BCP-47 language code for ``label``, such as "en-US" or - "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - """ - - label = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - - web_entities = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=WebEntity, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=WebImage, - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=WebImage, - ) - pages_with_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=WebPage, - ) - visually_similar_images = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=WebImage, - ) - best_guess_labels = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=WebLabel, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p2beta1/mypy.ini b/owl-bot-staging/v1p2beta1/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1p2beta1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1p2beta1/noxfile.py b/owl-bot-staging/v1p2beta1/noxfile.py deleted file mode 100644 index d8e69c5f..00000000 --- a/owl-bot-staging/v1p2beta1/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/vision_v1p2beta1/', - '--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/v1p2beta1/scripts/fixup_vision_v1p2beta1_keywords.py b/owl-bot-staging/v1p2beta1/scripts/fixup_vision_v1p2beta1_keywords.py deleted file mode 100644 index bae0aa90..00000000 --- a/owl-bot-staging/v1p2beta1/scripts/fixup_vision_v1p2beta1_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 visionCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'async_batch_annotate_files': ('requests', ), - 'batch_annotate_images': ('requests', ), - } - - 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: a.keyword.value not 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=visionCallTransformer(), -): - """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 vision 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/v1p2beta1/setup.py b/owl-bot-staging/v1p2beta1/setup.py deleted file mode 100644 index 9d03e702..00000000 --- a/owl-bot-staging/v1p2beta1/setup.py +++ /dev/null @@ -1,54 +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-vision', - 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, < 3.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', - 'Programming Language :: Python :: 3.9', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1p2beta1/tests/__init__.py b/owl-bot-staging/v1p2beta1/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p2beta1/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/v1p2beta1/tests/unit/__init__.py b/owl-bot-staging/v1p2beta1/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p2beta1/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/v1p2beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p2beta1/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p2beta1/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/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__init__.py b/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/__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/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py deleted file mode 100644 index 1af6142e..00000000 --- a/owl-bot-staging/v1p2beta1/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ /dev/null @@ -1,1341 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1p2beta1.services.image_annotator import ImageAnnotatorAsyncClient -from google.cloud.vision_v1p2beta1.services.image_annotator import ImageAnnotatorClient -from google.cloud.vision_v1p2beta1.services.image_annotator import transports -from google.cloud.vision_v1p2beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1p2beta1.types import image_annotator -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ImageAnnotatorGrpcTransport, "grpc"), - (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -def test_image_annotator_client_get_transport_class(): - transport = ImageAnnotatorClient.get_transport_class() - available_transports = [ - transports.ImageAnnotatorGrpcTransport, - ] - assert transport in available_transports - - transport = ImageAnnotatorClient.get_transport_class("grpc") - assert transport == transports.ImageAnnotatorGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - -def test_image_annotator_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ImageAnnotatorClient( - 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, - always_use_jwt_access=True, - ) - - -def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse( - ) - response = client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - -def test_batch_annotate_images_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 = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - client.batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( - )) - response = await client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async_from_dict(): - await test_batch_annotate_images_async(request_type=dict) - - -def test_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -def test_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - -def test_async_batch_annotate_files_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 = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - client.async_batch_annotate_files() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files), - '__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.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async_from_dict(): - await test_async_batch_annotate_files_async(request_type=dict) - - -def test_async_batch_annotate_files_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -def test_async_batch_annotate_files_flattened_error(): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ImageAnnotatorClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, -]) -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 = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ImageAnnotatorGrpcTransport, - ) - -def test_image_annotator_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_image_annotator_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'batch_annotate_images', - 'async_batch_annotate_files', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_image_annotator_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.vision_v1p2beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ImageAnnotatorGrpcTransport, grpc_helpers), - (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_image_annotator_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_host_no_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_image_annotator_host_with_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_image_annotator_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcTransport( - 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_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_grpc_lro_client(): - client = ImageAnnotatorClient( - 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_image_annotator_grpc_lro_async_client(): - client = ImageAnnotatorAsyncClient( - 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 = ImageAnnotatorClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ImageAnnotatorClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = ImageAnnotatorClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ImageAnnotatorClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ImageAnnotatorClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ImageAnnotatorClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = ImageAnnotatorClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ImageAnnotatorClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ImageAnnotatorClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - transport_class = ImageAnnotatorClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1p3beta1/.coveragerc b/owl-bot-staging/v1p3beta1/.coveragerc deleted file mode 100644 index 75747063..00000000 --- a/owl-bot-staging/v1p3beta1/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/vision/__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/v1p3beta1/MANIFEST.in b/owl-bot-staging/v1p3beta1/MANIFEST.in deleted file mode 100644 index 5c6705a2..00000000 --- a/owl-bot-staging/v1p3beta1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/vision *.py -recursive-include google/cloud/vision_v1p3beta1 *.py diff --git a/owl-bot-staging/v1p3beta1/README.rst b/owl-bot-staging/v1p3beta1/README.rst deleted file mode 100644 index 39f9ca72..00000000 --- a/owl-bot-staging/v1p3beta1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Vision 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 Vision 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/v1p3beta1/docs/conf.py b/owl-bot-staging/v1p3beta1/docs/conf.py deleted file mode 100644 index 6e730bf5..00000000 --- a/owl-bot-staging/v1p3beta1/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-vision 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-vision" -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-vision-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-vision.tex", - u"google-cloud-vision 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-vision", - u"Google Cloud Vision 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-vision", - u"google-cloud-vision Documentation", - author, - "google-cloud-vision", - "GAPIC library for Google Cloud Vision 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/v1p3beta1/docs/index.rst b/owl-bot-staging/v1p3beta1/docs/index.rst deleted file mode 100644 index 87acf3ca..00000000 --- a/owl-bot-staging/v1p3beta1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - vision_v1p3beta1/services - vision_v1p3beta1/types diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst deleted file mode 100644 index a5ed7542..00000000 --- a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/image_annotator.rst +++ /dev/null @@ -1,6 +0,0 @@ -ImageAnnotator --------------------------------- - -.. automodule:: google.cloud.vision_v1p3beta1.services.image_annotator - :members: - :inherited-members: diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst deleted file mode 100644 index 21e79602..00000000 --- a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/product_search.rst +++ /dev/null @@ -1,10 +0,0 @@ -ProductSearch -------------------------------- - -.. automodule:: google.cloud.vision_v1p3beta1.services.product_search - :members: - :inherited-members: - -.. automodule:: google.cloud.vision_v1p3beta1.services.product_search.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst deleted file mode 100644 index 06da9b3d..00000000 --- a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/services.rst +++ /dev/null @@ -1,7 +0,0 @@ -Services for Google Cloud Vision v1p3beta1 API -============================================== -.. toctree:: - :maxdepth: 2 - - image_annotator - product_search diff --git a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst b/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst deleted file mode 100644 index 5fdbaea1..00000000 --- a/owl-bot-staging/v1p3beta1/docs/vision_v1p3beta1/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Vision v1p3beta1 API -=========================================== - -.. automodule:: google.cloud.vision_v1p3beta1.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py deleted file mode 100644 index f3be6b83..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision/__init__.py +++ /dev/null @@ -1,187 +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.vision_v1p3beta1.services.image_annotator.client import ImageAnnotatorClient -from google.cloud.vision_v1p3beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient -from google.cloud.vision_v1p3beta1.services.product_search.client import ProductSearchClient -from google.cloud.vision_v1p3beta1.services.product_search.async_client import ProductSearchAsyncClient - -from google.cloud.vision_v1p3beta1.types.geometry import BoundingPoly -from google.cloud.vision_v1p3beta1.types.geometry import NormalizedBoundingPoly -from google.cloud.vision_v1p3beta1.types.geometry import NormalizedVertex -from google.cloud.vision_v1p3beta1.types.geometry import Position -from google.cloud.vision_v1p3beta1.types.geometry import Vertex -from google.cloud.vision_v1p3beta1.types.image_annotator import AnnotateFileResponse -from google.cloud.vision_v1p3beta1.types.image_annotator import AnnotateImageRequest -from google.cloud.vision_v1p3beta1.types.image_annotator import AnnotateImageResponse -from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncAnnotateFileRequest -from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncAnnotateFileResponse -from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncBatchAnnotateFilesRequest -from google.cloud.vision_v1p3beta1.types.image_annotator import AsyncBatchAnnotateFilesResponse -from google.cloud.vision_v1p3beta1.types.image_annotator import BatchAnnotateImagesRequest -from google.cloud.vision_v1p3beta1.types.image_annotator import BatchAnnotateImagesResponse -from google.cloud.vision_v1p3beta1.types.image_annotator import ColorInfo -from google.cloud.vision_v1p3beta1.types.image_annotator import CropHint -from google.cloud.vision_v1p3beta1.types.image_annotator import CropHintsAnnotation -from google.cloud.vision_v1p3beta1.types.image_annotator import CropHintsParams -from google.cloud.vision_v1p3beta1.types.image_annotator import DominantColorsAnnotation -from google.cloud.vision_v1p3beta1.types.image_annotator import EntityAnnotation -from google.cloud.vision_v1p3beta1.types.image_annotator import FaceAnnotation -from google.cloud.vision_v1p3beta1.types.image_annotator import Feature -from google.cloud.vision_v1p3beta1.types.image_annotator import GcsDestination -from google.cloud.vision_v1p3beta1.types.image_annotator import GcsSource -from google.cloud.vision_v1p3beta1.types.image_annotator import Image -from google.cloud.vision_v1p3beta1.types.image_annotator import ImageAnnotationContext -from google.cloud.vision_v1p3beta1.types.image_annotator import ImageContext -from google.cloud.vision_v1p3beta1.types.image_annotator import ImageProperties -from google.cloud.vision_v1p3beta1.types.image_annotator import ImageSource -from google.cloud.vision_v1p3beta1.types.image_annotator import InputConfig -from google.cloud.vision_v1p3beta1.types.image_annotator import LatLongRect -from google.cloud.vision_v1p3beta1.types.image_annotator import LocalizedObjectAnnotation -from google.cloud.vision_v1p3beta1.types.image_annotator import LocationInfo -from google.cloud.vision_v1p3beta1.types.image_annotator import OperationMetadata -from google.cloud.vision_v1p3beta1.types.image_annotator import OutputConfig -from google.cloud.vision_v1p3beta1.types.image_annotator import Property -from google.cloud.vision_v1p3beta1.types.image_annotator import SafeSearchAnnotation -from google.cloud.vision_v1p3beta1.types.image_annotator import TextDetectionParams -from google.cloud.vision_v1p3beta1.types.image_annotator import WebDetectionParams -from google.cloud.vision_v1p3beta1.types.image_annotator import Likelihood -from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchParams -from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchResults -from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchCategory -from google.cloud.vision_v1p3beta1.types.product_search import ProductSearchResultsView -from google.cloud.vision_v1p3beta1.types.product_search_service import AddProductToProductSetRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import BatchOperationMetadata -from google.cloud.vision_v1p3beta1.types.product_search_service import CreateProductRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import CreateProductSetRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import CreateReferenceImageRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import DeleteProductRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import DeleteProductSetRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import DeleteReferenceImageRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import GetProductRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import GetProductSetRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import GetReferenceImageRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsGcsSource -from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsInputConfig -from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import ImportProductSetsResponse -from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductSetsRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductSetsResponse -from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsInProductSetRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsInProductSetResponse -from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import ListProductsResponse -from google.cloud.vision_v1p3beta1.types.product_search_service import ListReferenceImagesRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import ListReferenceImagesResponse -from google.cloud.vision_v1p3beta1.types.product_search_service import Product -from google.cloud.vision_v1p3beta1.types.product_search_service import ProductSet -from google.cloud.vision_v1p3beta1.types.product_search_service import ReferenceImage -from google.cloud.vision_v1p3beta1.types.product_search_service import RemoveProductFromProductSetRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import UpdateProductRequest -from google.cloud.vision_v1p3beta1.types.product_search_service import UpdateProductSetRequest -from google.cloud.vision_v1p3beta1.types.text_annotation import Block -from google.cloud.vision_v1p3beta1.types.text_annotation import Page -from google.cloud.vision_v1p3beta1.types.text_annotation import Paragraph -from google.cloud.vision_v1p3beta1.types.text_annotation import Symbol -from google.cloud.vision_v1p3beta1.types.text_annotation import TextAnnotation -from google.cloud.vision_v1p3beta1.types.text_annotation import Word -from google.cloud.vision_v1p3beta1.types.web_detection import WebDetection - -__all__ = ('ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', - 'ProductSearchClient', - 'ProductSearchAsyncClient', - 'BoundingPoly', - 'NormalizedBoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocalizedObjectAnnotation', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'ProductSearchParams', - 'ProductSearchResults', - 'ProductSearchCategory', - 'ProductSearchResultsView', - 'AddProductToProductSetRequest', - 'BatchOperationMetadata', - 'CreateProductRequest', - 'CreateProductSetRequest', - 'CreateReferenceImageRequest', - 'DeleteProductRequest', - 'DeleteProductSetRequest', - 'DeleteReferenceImageRequest', - 'GetProductRequest', - 'GetProductSetRequest', - 'GetReferenceImageRequest', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ListProductsRequest', - 'ListProductsResponse', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'Product', - 'ProductSet', - 'ReferenceImage', - 'RemoveProductFromProductSetRequest', - 'UpdateProductRequest', - 'UpdateProductSetRequest', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py deleted file mode 100644 index db381a13..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/__init__.py +++ /dev/null @@ -1,188 +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.image_annotator import ImageAnnotatorClient -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.product_search import ProductSearchClient -from .services.product_search import ProductSearchAsyncClient - -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedBoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Position -from .types.geometry import Vertex -from .types.image_annotator import AnnotateFileResponse -from .types.image_annotator import AnnotateImageRequest -from .types.image_annotator import AnnotateImageResponse -from .types.image_annotator import AsyncAnnotateFileRequest -from .types.image_annotator import AsyncAnnotateFileResponse -from .types.image_annotator import AsyncBatchAnnotateFilesRequest -from .types.image_annotator import AsyncBatchAnnotateFilesResponse -from .types.image_annotator import BatchAnnotateImagesRequest -from .types.image_annotator import BatchAnnotateImagesResponse -from .types.image_annotator import ColorInfo -from .types.image_annotator import CropHint -from .types.image_annotator import CropHintsAnnotation -from .types.image_annotator import CropHintsParams -from .types.image_annotator import DominantColorsAnnotation -from .types.image_annotator import EntityAnnotation -from .types.image_annotator import FaceAnnotation -from .types.image_annotator import Feature -from .types.image_annotator import GcsDestination -from .types.image_annotator import GcsSource -from .types.image_annotator import Image -from .types.image_annotator import ImageAnnotationContext -from .types.image_annotator import ImageContext -from .types.image_annotator import ImageProperties -from .types.image_annotator import ImageSource -from .types.image_annotator import InputConfig -from .types.image_annotator import LatLongRect -from .types.image_annotator import LocalizedObjectAnnotation -from .types.image_annotator import LocationInfo -from .types.image_annotator import OperationMetadata -from .types.image_annotator import OutputConfig -from .types.image_annotator import Property -from .types.image_annotator import SafeSearchAnnotation -from .types.image_annotator import TextDetectionParams -from .types.image_annotator import WebDetectionParams -from .types.image_annotator import Likelihood -from .types.product_search import ProductSearchParams -from .types.product_search import ProductSearchResults -from .types.product_search import ProductSearchCategory -from .types.product_search import ProductSearchResultsView -from .types.product_search_service import AddProductToProductSetRequest -from .types.product_search_service import BatchOperationMetadata -from .types.product_search_service import CreateProductRequest -from .types.product_search_service import CreateProductSetRequest -from .types.product_search_service import CreateReferenceImageRequest -from .types.product_search_service import DeleteProductRequest -from .types.product_search_service import DeleteProductSetRequest -from .types.product_search_service import DeleteReferenceImageRequest -from .types.product_search_service import GetProductRequest -from .types.product_search_service import GetProductSetRequest -from .types.product_search_service import GetReferenceImageRequest -from .types.product_search_service import ImportProductSetsGcsSource -from .types.product_search_service import ImportProductSetsInputConfig -from .types.product_search_service import ImportProductSetsRequest -from .types.product_search_service import ImportProductSetsResponse -from .types.product_search_service import ListProductSetsRequest -from .types.product_search_service import ListProductSetsResponse -from .types.product_search_service import ListProductsInProductSetRequest -from .types.product_search_service import ListProductsInProductSetResponse -from .types.product_search_service import ListProductsRequest -from .types.product_search_service import ListProductsResponse -from .types.product_search_service import ListReferenceImagesRequest -from .types.product_search_service import ListReferenceImagesResponse -from .types.product_search_service import Product -from .types.product_search_service import ProductSet -from .types.product_search_service import ReferenceImage -from .types.product_search_service import RemoveProductFromProductSetRequest -from .types.product_search_service import UpdateProductRequest -from .types.product_search_service import UpdateProductSetRequest -from .types.text_annotation import Block -from .types.text_annotation import Page -from .types.text_annotation import Paragraph -from .types.text_annotation import Symbol -from .types.text_annotation import TextAnnotation -from .types.text_annotation import Word -from .types.web_detection import WebDetection - -__all__ = ( - 'ImageAnnotatorAsyncClient', - 'ProductSearchAsyncClient', -'AddProductToProductSetRequest', -'AnnotateFileResponse', -'AnnotateImageRequest', -'AnnotateImageResponse', -'AsyncAnnotateFileRequest', -'AsyncAnnotateFileResponse', -'AsyncBatchAnnotateFilesRequest', -'AsyncBatchAnnotateFilesResponse', -'BatchAnnotateImagesRequest', -'BatchAnnotateImagesResponse', -'BatchOperationMetadata', -'Block', -'BoundingPoly', -'ColorInfo', -'CreateProductRequest', -'CreateProductSetRequest', -'CreateReferenceImageRequest', -'CropHint', -'CropHintsAnnotation', -'CropHintsParams', -'DeleteProductRequest', -'DeleteProductSetRequest', -'DeleteReferenceImageRequest', -'DominantColorsAnnotation', -'EntityAnnotation', -'FaceAnnotation', -'Feature', -'GcsDestination', -'GcsSource', -'GetProductRequest', -'GetProductSetRequest', -'GetReferenceImageRequest', -'Image', -'ImageAnnotationContext', -'ImageAnnotatorClient', -'ImageContext', -'ImageProperties', -'ImageSource', -'ImportProductSetsGcsSource', -'ImportProductSetsInputConfig', -'ImportProductSetsRequest', -'ImportProductSetsResponse', -'InputConfig', -'LatLongRect', -'Likelihood', -'ListProductSetsRequest', -'ListProductSetsResponse', -'ListProductsInProductSetRequest', -'ListProductsInProductSetResponse', -'ListProductsRequest', -'ListProductsResponse', -'ListReferenceImagesRequest', -'ListReferenceImagesResponse', -'LocalizedObjectAnnotation', -'LocationInfo', -'NormalizedBoundingPoly', -'NormalizedVertex', -'OperationMetadata', -'OutputConfig', -'Page', -'Paragraph', -'Position', -'Product', -'ProductSearchCategory', -'ProductSearchClient', -'ProductSearchParams', -'ProductSearchResults', -'ProductSearchResultsView', -'ProductSet', -'Property', -'ReferenceImage', -'RemoveProductFromProductSetRequest', -'SafeSearchAnnotation', -'Symbol', -'TextAnnotation', -'TextDetectionParams', -'UpdateProductRequest', -'UpdateProductSetRequest', -'Vertex', -'WebDetection', -'WebDetectionParams', -'Word', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json deleted file mode 100644 index a1425044..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/gapic_metadata.json +++ /dev/null @@ -1,237 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.vision_v1p3beta1", - "protoPackage": "google.cloud.vision.v1p3beta1", - "schema": "1.0", - "services": { - "ImageAnnotator": { - "clients": { - "grpc": { - "libraryClient": "ImageAnnotatorClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ImageAnnotatorAsyncClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - } - } - }, - "ProductSearch": { - "clients": { - "grpc": { - "libraryClient": "ProductSearchClient", - "rpcs": { - "AddProductToProductSet": { - "methods": [ - "add_product_to_product_set" - ] - }, - "CreateProduct": { - "methods": [ - "create_product" - ] - }, - "CreateProductSet": { - "methods": [ - "create_product_set" - ] - }, - "CreateReferenceImage": { - "methods": [ - "create_reference_image" - ] - }, - "DeleteProduct": { - "methods": [ - "delete_product" - ] - }, - "DeleteProductSet": { - "methods": [ - "delete_product_set" - ] - }, - "DeleteReferenceImage": { - "methods": [ - "delete_reference_image" - ] - }, - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "GetProductSet": { - "methods": [ - "get_product_set" - ] - }, - "GetReferenceImage": { - "methods": [ - "get_reference_image" - ] - }, - "ImportProductSets": { - "methods": [ - "import_product_sets" - ] - }, - "ListProductSets": { - "methods": [ - "list_product_sets" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - }, - "ListProductsInProductSet": { - "methods": [ - "list_products_in_product_set" - ] - }, - "ListReferenceImages": { - "methods": [ - "list_reference_images" - ] - }, - "RemoveProductFromProductSet": { - "methods": [ - "remove_product_from_product_set" - ] - }, - "UpdateProduct": { - "methods": [ - "update_product" - ] - }, - "UpdateProductSet": { - "methods": [ - "update_product_set" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ProductSearchAsyncClient", - "rpcs": { - "AddProductToProductSet": { - "methods": [ - "add_product_to_product_set" - ] - }, - "CreateProduct": { - "methods": [ - "create_product" - ] - }, - "CreateProductSet": { - "methods": [ - "create_product_set" - ] - }, - "CreateReferenceImage": { - "methods": [ - "create_reference_image" - ] - }, - "DeleteProduct": { - "methods": [ - "delete_product" - ] - }, - "DeleteProductSet": { - "methods": [ - "delete_product_set" - ] - }, - "DeleteReferenceImage": { - "methods": [ - "delete_reference_image" - ] - }, - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "GetProductSet": { - "methods": [ - "get_product_set" - ] - }, - "GetReferenceImage": { - "methods": [ - "get_reference_image" - ] - }, - "ImportProductSets": { - "methods": [ - "import_product_sets" - ] - }, - "ListProductSets": { - "methods": [ - "list_product_sets" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - }, - "ListProductsInProductSet": { - "methods": [ - "list_products_in_product_set" - ] - }, - "ListReferenceImages": { - "methods": [ - "list_reference_images" - ] - }, - "RemoveProductFromProductSet": { - "methods": [ - "remove_product_from_product_set" - ] - }, - "UpdateProduct": { - "methods": [ - "update_product" - ] - }, - "UpdateProductSet": { - "methods": [ - "update_product_set" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/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/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__init__.py deleted file mode 100644 index 3cbfa2fa..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/__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 ImageAnnotatorClient -from .async_client import ImageAnnotatorAsyncClient - -__all__ = ( - 'ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py deleted file mode 100644 index 08b9e34a..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/async_client.py +++ /dev/null @@ -1,336 +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.vision_v1p3beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport -from .client import ImageAnnotatorClient - - -class ImageAnnotatorAsyncClient: - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - _client: ImageAnnotatorClient - - DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT - - product_path = staticmethod(ImageAnnotatorClient.product_path) - parse_product_path = staticmethod(ImageAnnotatorClient.parse_product_path) - product_set_path = staticmethod(ImageAnnotatorClient.product_set_path) - parse_product_set_path = staticmethod(ImageAnnotatorClient.parse_product_set_path) - common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) - parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) - common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) - parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) - common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) - parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) - common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) - parse_common_location_path = staticmethod(ImageAnnotatorClient.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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def batch_annotate_images(self, - request: image_annotator.BatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest`): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]`): - Individual image annotation requests - for this batch. - - 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.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def async_batch_annotate_files(self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest`): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]`): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1p3beta1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorAsyncClient", -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py deleted file mode 100644 index f28deb03..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/client.py +++ /dev/null @@ -1,530 +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 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.vision_v1p3beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ImageAnnotatorGrpcTransport -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -class ImageAnnotatorClientMeta(type): - """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] - _transport_registry["grpc"] = ImageAnnotatorGrpcTransport - _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ImageAnnotatorTransport]: - """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - @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 = "vision.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: - ImageAnnotatorClient: 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: - ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(project: str,location: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_set_path(project: str,location: str,product_set: str,) -> str: - """Returns a fully-qualified product_set string.""" - return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - - @staticmethod - def parse_product_set_path(path: str) -> Dict[str,str]: - """Parses a product_set path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?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, ImageAnnotatorTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): - # transport is a ImageAnnotatorTransport 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, - always_use_jwt_access=True, - ) - - def batch_annotate_images(self, - request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.BatchAnnotateImagesRequest, dict]): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]): - Individual image annotation requests - for this batch. - - 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.cloud.vision_v1p3beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 image_annotator.BatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): - request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def async_batch_annotate_files(self, - request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.AsyncBatchAnnotateFilesRequest, dict]): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1p3beta1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 image_annotator.AsyncBatchAnnotateFilesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): - request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorClient", -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/__init__.py deleted file mode 100644 index 94f01250..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/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 ImageAnnotatorTransport -from .grpc import ImageAnnotatorGrpcTransport -from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] -_transport_registry['grpc'] = ImageAnnotatorGrpcTransport -_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport - -__all__ = ( - 'ImageAnnotatorTransport', - 'ImageAnnotatorGrpcTransport', - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py deleted file mode 100644 index 0e5d068d..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/base.py +++ /dev/null @@ -1,211 +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.vision_v1p3beta1.types import image_annotator -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-vision', - ).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 ImageAnnotatorTransport(abc.ABC): - """Abstract transport class for ImageAnnotator.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( - self.batch_annotate_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.async_batch_annotate_files: gapic_v1.method.wrap_method( - self.async_batch_annotate_files, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Union[ - image_annotator.BatchAnnotateImagesResponse, - Awaitable[image_annotator.BatchAnnotateImagesResponse] - ]]: - raise NotImplementedError() - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ImageAnnotatorTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.py deleted file mode 100644 index 790b47d3..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc.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 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.vision_v1p3beta1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO - - -class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): - """gRPC backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - image_annotator.BatchAnnotateImagesResponse]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - ~.BatchAnnotateImagesResponse]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - operations_pb2.Operation]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - ~.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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ImageAnnotatorGrpcTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py deleted file mode 100644 index aabeb507..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/image_annotator/transports/grpc_asyncio.py +++ /dev/null @@ -1,314 +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.vision_v1p3beta1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .grpc import ImageAnnotatorGrpcTransport - - -class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): - """gRPC AsyncIO backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Awaitable[image_annotator.BatchAnnotateImagesResponse]]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - Awaitable[~.BatchAnnotateImagesResponse]]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - 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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__init__.py deleted file mode 100644 index cf79a54d..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/__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 ProductSearchClient -from .async_client import ProductSearchAsyncClient - -__all__ = ( - 'ProductSearchClient', - 'ProductSearchAsyncClient', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py deleted file mode 100644 index f9d093b2..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/async_client.py +++ /dev/null @@ -1,1988 +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.vision_v1p3beta1.services.product_search import pagers -from google.cloud.vision_v1p3beta1.types import geometry -from google.cloud.vision_v1p3beta1.types import product_search_service -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport -from .client import ProductSearchClient - - -class ProductSearchAsyncClient: - """Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - """ - - _client: ProductSearchClient - - DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT - - product_path = staticmethod(ProductSearchClient.product_path) - parse_product_path = staticmethod(ProductSearchClient.parse_product_path) - product_set_path = staticmethod(ProductSearchClient.product_set_path) - parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) - reference_image_path = staticmethod(ProductSearchClient.reference_image_path) - parse_reference_image_path = staticmethod(ProductSearchClient.parse_reference_image_path) - common_billing_account_path = staticmethod(ProductSearchClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductSearchClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ProductSearchClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductSearchClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductSearchClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductSearchClient.parse_common_organization_path) - common_project_path = staticmethod(ProductSearchClient.common_project_path) - parse_common_project_path = staticmethod(ProductSearchClient.parse_common_project_path) - common_location_path = staticmethod(ProductSearchClient.common_location_path) - parse_common_location_path = staticmethod(ProductSearchClient.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: - ProductSearchAsyncClient: The constructed client. - """ - return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, 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: - ProductSearchAsyncClient: The constructed client. - """ - return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ProductSearchTransport: - """Returns the transport used by the client instance. - - Returns: - ProductSearchTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ProductSearchClient).get_transport_class, type(ProductSearchClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ProductSearchTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product search 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, ~.ProductSearchTransport]): 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 = ProductSearchClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def create_product_set(self, - request: product_search_service.CreateProductSetRequest = None, - *, - parent: str = None, - product_set: product_search_service.ProductSet = None, - product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductSetRequest`): - The request object. Request message for the - `CreateProductSet` method. - parent (:class:`str`): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): - Required. The ProductSet to create. - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set_id (:class:`str`): - A user-supplied resource id for this ProductSet. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_set_id`` 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.vision_v1p3beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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, product_set, product_set_id]) - 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 = product_search_service.CreateProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product_set is not None: - request.product_set = product_set - if product_set_id is not None: - request.product_set_id = product_set_id - - # 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_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def list_product_sets(self, - request: product_search_service.ListProductSetsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductSetsAsyncPager: - r"""Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListProductSetsRequest`): - The request object. Request message for the - `ListProductSets` method. - parent (:class:`str`): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.vision_v1p3beta1.services.product_search.pagers.ListProductSetsAsyncPager: - Response message for the ListProductSets method. - - 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 = product_search_service.ListProductSetsRequest(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_product_sets, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductSetsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_product_set(self, - request: product_search_service.GetProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.GetProductSetRequest`): - The request object. Request message for the - `GetProductSet` method. - name (:class:`str`): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p3beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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 = product_search_service.GetProductSetRequest(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.get_product_set, - 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=600.0, - ), - default_timeout=600.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 update_product_set(self, - request: product_search_service.UpdateProductSetRequest = None, - *, - product_set: product_search_service.ProductSet = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest`): - The request object. Request message for the - `UpdateProductSet` method. - product_set (:class:`google.cloud.vision_v1p3beta1.types.ProductSet`): - Required. The ProductSet resource - which replaces the one on the server. - - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask path is ``display_name``. - - This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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([product_set, update_mask]) - 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 = product_search_service.UpdateProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_set is not None: - request.product_set = product_set - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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(( - ("product_set.name", request.product_set.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product_set(self, - request: product_search_service.DeleteProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a ProductSet. All Products and - ReferenceImages in the ProductSet will be deleted. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest`): - The request object. Request message for the - `DeleteProductSet` method. - name (:class:`str`): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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. - """ - # 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 = product_search_service.DeleteProductSetRequest(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_product_set, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def create_product(self, - request: product_search_service.CreateProductRequest = None, - *, - parent: str = None, - product: product_search_service.Product = None, - product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.CreateProductRequest`): - The request object. Request message for the - `CreateProduct` method. - parent (:class:`str`): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`google.cloud.vision_v1p3beta1.types.Product`): - Required. The product to create. - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_id (:class:`str`): - A user-supplied resource id for this Product. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_id`` 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.vision_v1p3beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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, product, product_id]) - 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 = product_search_service.CreateProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product is not None: - request.product = product - if product_id is not None: - request.product_id = product_id - - # 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_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def list_products(self, - request: product_search_service.ListProductsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsAsyncPager: - r"""Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsRequest`): - The request object. Request message for the - `ListProducts` method. - parent (:class:`str`): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - - 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.vision_v1p3beta1.services.product_search.pagers.ListProductsAsyncPager: - Response message for the ListProducts method. - - 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 = product_search_service.ListProductsRequest(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_products, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_product(self, - request: product_search_service.GetProductRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.GetProductRequest`): - The request object. Request message for the `GetProduct` - method. - name (:class:`str`): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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.vision_v1p3beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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 = product_search_service.GetProductRequest(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.get_product, - 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=600.0, - ), - default_timeout=600.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 update_product(self, - request: product_search_service.UpdateProductRequest = None, - *, - product: product_search_service.Product = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Makes changes to a Product resource. Only display_name, - description and labels can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.UpdateProductRequest`): - The request object. Request message for the - `UpdateProduct` method. - product (:class:`google.cloud.vision_v1p3beta1.types.Product`): - Required. The Product resource which - replaces the one on the server. - product.name is immutable. - - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask paths include ``product_labels``, ``display_name``, - and ``description``. - - This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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([product, update_mask]) - 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 = product_search_service.UpdateProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product is not None: - request.product = product - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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(( - ("product.name", request.product.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product(self, - request: product_search_service.DeleteProductRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a product and its reference images. - - Metadata of the product and all its images will be deleted right - away, but search queries against ProductSets containing the - product may still work until all related caches are refreshed. - - Possible errors: - - - Returns NOT_FOUND if the product does not exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.DeleteProductRequest`): - The request object. Request message for the - `DeleteProduct` method. - name (:class:`str`): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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. - """ - # 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 = product_search_service.DeleteProductRequest(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_product, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def create_reference_image(self, - request: product_search_service.CreateReferenceImageRequest = None, - *, - parent: str = None, - reference_image: product_search_service.ReferenceImage = None, - reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest`): - The request object. Request message for the - `CreateReferenceImage` method. - parent (:class:`str`): - Required. Resource name of the product in which to - create the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image (:class:`google.cloud.vision_v1p3beta1.types.ReferenceImage`): - Required. The reference image to - create. If an image ID is specified, it - is ignored. - - This corresponds to the ``reference_image`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image_id (:class:`str`): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value - as the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``reference_image_id`` 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.vision_v1p3beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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, reference_image, reference_image_id]) - 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 = product_search_service.CreateReferenceImageRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if reference_image is not None: - request.reference_image = reference_image - if reference_image_id is not None: - request.reference_image_id = reference_image_id - - # 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_reference_image, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def delete_reference_image(self, - request: product_search_service.DeleteReferenceImageRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a reference image. - - The image metadata will be deleted right away, but search - queries against ProductSets containing the image may still work - until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the reference image does not exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest`): - The request object. Request message for the - `DeleteReferenceImage` method. - name (:class:`str`): - Required. The resource name of the reference image to - delete. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - - 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. - """ - # 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 = product_search_service.DeleteReferenceImageRequest(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_reference_image, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_reference_images(self, - request: product_search_service.ListReferenceImagesRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListReferenceImagesAsyncPager: - r"""Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest`): - The request object. Request message for the - `ListReferenceImages` method. - parent (:class:`str`): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - 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.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: - Response message for the ListReferenceImages method. - - 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 = product_search_service.ListReferenceImagesRequest(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_reference_images, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListReferenceImagesAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_reference_image(self, - request: product_search_service.GetReferenceImageRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest`): - The request object. Request message for the - `GetReferenceImage` method. - name (:class:`str`): - Required. The resource name of the ReferenceImage to - get. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - 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.vision_v1p3beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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 = product_search_service.GetReferenceImageRequest(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.get_reference_image, - 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=600.0, - ), - default_timeout=600.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 add_product_to_product_set(self, - request: product_search_service.AddProductToProductSetRequest = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest`): - The request object. Request message for the - `AddProductToProductSet` method. - name (:class:`str`): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`str`): - Required. The resource name for the Product to be added - to this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 = product_search_service.AddProductToProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.add_product_to_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def remove_product_from_product_set(self, - request: product_search_service.RemoveProductFromProductSetRequest = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Removes a Product from the specified ProductSet. - - Possible errors: - - - Returns NOT_FOUND If the Product is not found under the - ProductSet. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest`): - The request object. Request message for the - `RemoveProductFromProductSet` method. - name (:class:`str`): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`str`): - Required. The resource name for the Product to be - removed from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 = product_search_service.RemoveProductFromProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.remove_product_from_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_products_in_product_set(self, - request: product_search_service.ListProductsInProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsInProductSetAsyncPager: - r"""Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest`): - The request object. Request message for the - `ListProductsInProductSet` method. - name (:class:`str`): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: - Response message for the ListProductsInProductSet - method. - - 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([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 = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsInProductSetAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def import_product_sets(self, - request: product_search_service.ImportProductSetsRequest = None, - *, - parent: str = None, - input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Args: - request (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest`): - The request object. Request message for the - `ImportProductSets` method. - parent (:class:`str`): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - input_config (:class:`google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig`): - Required. The input content for the - list of requests. - - This corresponds to the ``input_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.vision_v1p3beta1.types.ImportProductSetsResponse` - Response message for the ImportProductSets method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - """ - # 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, input_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 = product_search_service.ImportProductSetsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if input_config is not None: - request.input_config = input_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.import_product_sets, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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, - product_search_service.ImportProductSetsResponse, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ProductSearchAsyncClient", -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py deleted file mode 100644 index ad053367..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/client.py +++ /dev/null @@ -1,2093 +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 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.vision_v1p3beta1.services.product_search import pagers -from google.cloud.vision_v1p3beta1.types import geometry -from google.cloud.vision_v1p3beta1.types import product_search_service -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ProductSearchGrpcTransport -from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport - - -class ProductSearchClientMeta(type): - """Metaclass for the ProductSearch 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[ProductSearchTransport]] - _transport_registry["grpc"] = ProductSearchGrpcTransport - _transport_registry["grpc_asyncio"] = ProductSearchGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ProductSearchTransport]: - """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 ProductSearchClient(metaclass=ProductSearchClientMeta): - """Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - """ - - @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 = "vision.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: - ProductSearchClient: 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: - ProductSearchClient: 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) -> ProductSearchTransport: - """Returns the transport used by the client instance. - - Returns: - ProductSearchTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(project: str,location: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_set_path(project: str,location: str,product_set: str,) -> str: - """Returns a fully-qualified product_set string.""" - return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - - @staticmethod - def parse_product_set_path(path: str) -> Dict[str,str]: - """Parses a product_set path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def reference_image_path(project: str,location: str,product: str,reference_image: str,) -> str: - """Returns a fully-qualified reference_image string.""" - return "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) - - @staticmethod - def parse_reference_image_path(path: str) -> Dict[str,str]: - """Parses a reference_image path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)/referenceImages/(?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, ProductSearchTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product search 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, ProductSearchTransport]): 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, ProductSearchTransport): - # transport is a ProductSearchTransport 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, - always_use_jwt_access=True, - ) - - def create_product_set(self, - request: Union[product_search_service.CreateProductSetRequest, dict] = None, - *, - parent: str = None, - product_set: product_search_service.ProductSet = None, - product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.CreateProductSetRequest, dict]): - The request object. Request message for the - `CreateProductSet` method. - parent (str): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set (google.cloud.vision_v1p3beta1.types.ProductSet): - Required. The ProductSet to create. - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set_id (str): - A user-supplied resource id for this ProductSet. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_set_id`` 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.vision_v1p3beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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, product_set, product_set_id]) - 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 product_search_service.CreateProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateProductSetRequest): - request = product_search_service.CreateProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product_set is not None: - request.product_set = product_set - if product_set_id is not None: - request.product_set_id = product_set_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_product_set] - - # 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_product_sets(self, - request: Union[product_search_service.ListProductSetsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductSetsPager: - r"""Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.ListProductSetsRequest, dict]): - The request object. Request message for the - `ListProductSets` method. - parent (str): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.vision_v1p3beta1.services.product_search.pagers.ListProductSetsPager: - Response message for the ListProductSets method. - - 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 product_search_service.ListProductSetsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductSetsRequest): - request = product_search_service.ListProductSetsRequest(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_product_sets] - - # 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.ListProductSetsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_product_set(self, - request: Union[product_search_service.GetProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.GetProductSetRequest, dict]): - The request object. Request message for the - `GetProductSet` method. - name (str): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p3beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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 product_search_service.GetProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetProductSetRequest): - request = product_search_service.GetProductSetRequest(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.get_product_set] - - # 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 update_product_set(self, - request: Union[product_search_service.UpdateProductSetRequest, dict] = None, - *, - product_set: product_search_service.ProductSet = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductSetRequest, dict]): - The request object. Request message for the - `UpdateProductSet` method. - product_set (google.cloud.vision_v1p3beta1.types.ProductSet): - Required. The ProductSet resource - which replaces the one on the server. - - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask path is ``display_name``. - - This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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([product_set, update_mask]) - 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 product_search_service.UpdateProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.UpdateProductSetRequest): - request = product_search_service.UpdateProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_set is not None: - request.product_set = product_set - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product_set] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_set.name", request.product_set.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product_set(self, - request: Union[product_search_service.DeleteProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a ProductSet. All Products and - ReferenceImages in the ProductSet will be deleted. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductSetRequest, dict]): - The request object. Request message for the - `DeleteProductSet` method. - name (str): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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. - """ - # 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 product_search_service.DeleteProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteProductSetRequest): - request = product_search_service.DeleteProductSetRequest(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_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def create_product(self, - request: Union[product_search_service.CreateProductRequest, dict] = None, - *, - parent: str = None, - product: product_search_service.Product = None, - product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.CreateProductRequest, dict]): - The request object. Request message for the - `CreateProduct` method. - parent (str): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (google.cloud.vision_v1p3beta1.types.Product): - Required. The product to create. - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_id (str): - A user-supplied resource id for this Product. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_id`` 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.vision_v1p3beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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, product, product_id]) - 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 product_search_service.CreateProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateProductRequest): - request = product_search_service.CreateProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product is not None: - request.product = product - if product_id is not None: - request.product_id = product_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_product] - - # 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_products(self, - request: Union[product_search_service.ListProductsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsPager: - r"""Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.ListProductsRequest, dict]): - The request object. Request message for the - `ListProducts` method. - parent (str): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - - 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.vision_v1p3beta1.services.product_search.pagers.ListProductsPager: - Response message for the ListProducts method. - - 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 product_search_service.ListProductsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductsRequest): - request = product_search_service.ListProductsRequest(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_products] - - # 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.ListProductsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_product(self, - request: Union[product_search_service.GetProductRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.GetProductRequest, dict]): - The request object. Request message for the `GetProduct` - method. - name (str): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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.vision_v1p3beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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 product_search_service.GetProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetProductRequest): - request = product_search_service.GetProductRequest(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.get_product] - - # 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 update_product(self, - request: Union[product_search_service.UpdateProductRequest, dict] = None, - *, - product: product_search_service.Product = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Makes changes to a Product resource. Only display_name, - description and labels can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.UpdateProductRequest, dict]): - The request object. Request message for the - `UpdateProduct` method. - product (google.cloud.vision_v1p3beta1.types.Product): - Required. The Product resource which - replaces the one on the server. - product.name is immutable. - - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask paths include ``product_labels``, ``display_name``, - and ``description``. - - This corresponds to the ``update_mask`` 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.vision_v1p3beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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([product, update_mask]) - 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 product_search_service.UpdateProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.UpdateProductRequest): - request = product_search_service.UpdateProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product is not None: - request.product = product - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product.name", request.product.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product(self, - request: Union[product_search_service.DeleteProductRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a product and its reference images. - - Metadata of the product and all its images will be deleted right - away, but search queries against ProductSets containing the - product may still work until all related caches are refreshed. - - Possible errors: - - - Returns NOT_FOUND if the product does not exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.DeleteProductRequest, dict]): - The request object. Request message for the - `DeleteProduct` method. - name (str): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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. - """ - # 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 product_search_service.DeleteProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteProductRequest): - request = product_search_service.DeleteProductRequest(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_product] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def create_reference_image(self, - request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, - *, - parent: str = None, - reference_image: product_search_service.ReferenceImage = None, - reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.CreateReferenceImageRequest, dict]): - The request object. Request message for the - `CreateReferenceImage` method. - parent (str): - Required. Resource name of the product in which to - create the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image (google.cloud.vision_v1p3beta1.types.ReferenceImage): - Required. The reference image to - create. If an image ID is specified, it - is ignored. - - This corresponds to the ``reference_image`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image_id (str): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value - as the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``reference_image_id`` 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.vision_v1p3beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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, reference_image, reference_image_id]) - 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 product_search_service.CreateReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateReferenceImageRequest): - request = product_search_service.CreateReferenceImageRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if reference_image is not None: - request.reference_image = reference_image - if reference_image_id is not None: - request.reference_image_id = reference_image_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_reference_image] - - # 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_reference_image(self, - request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a reference image. - - The image metadata will be deleted right away, but search - queries against ProductSets containing the image may still work - until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the reference image does not exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.DeleteReferenceImageRequest, dict]): - The request object. Request message for the - `DeleteReferenceImage` method. - name (str): - Required. The resource name of the reference image to - delete. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - - 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. - """ - # 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 product_search_service.DeleteReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteReferenceImageRequest): - request = product_search_service.DeleteReferenceImageRequest(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_reference_image] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_reference_images(self, - request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListReferenceImagesPager: - r"""Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.ListReferenceImagesRequest, dict]): - The request object. Request message for the - `ListReferenceImages` method. - parent (str): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - 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.vision_v1p3beta1.services.product_search.pagers.ListReferenceImagesPager: - Response message for the ListReferenceImages method. - - 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 product_search_service.ListReferenceImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListReferenceImagesRequest): - request = product_search_service.ListReferenceImagesRequest(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_reference_images] - - # 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.ListReferenceImagesPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_reference_image(self, - request: Union[product_search_service.GetReferenceImageRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.GetReferenceImageRequest, dict]): - The request object. Request message for the - `GetReferenceImage` method. - name (str): - Required. The resource name of the ReferenceImage to - get. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - 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.vision_v1p3beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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 product_search_service.GetReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetReferenceImageRequest): - request = product_search_service.GetReferenceImageRequest(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.get_reference_image] - - # 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 add_product_to_product_set(self, - request: Union[product_search_service.AddProductToProductSetRequest, dict] = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.AddProductToProductSetRequest, dict]): - The request object. Request message for the - `AddProductToProductSet` method. - name (str): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (str): - Required. The resource name for the Product to be added - to this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 product_search_service.AddProductToProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.AddProductToProductSetRequest): - request = product_search_service.AddProductToProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.add_product_to_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def remove_product_from_product_set(self, - request: Union[product_search_service.RemoveProductFromProductSetRequest, dict] = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Removes a Product from the specified ProductSet. - - Possible errors: - - - Returns NOT_FOUND If the Product is not found under the - ProductSet. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.RemoveProductFromProductSetRequest, dict]): - The request object. Request message for the - `RemoveProductFromProductSet` method. - name (str): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (str): - Required. The resource name for the Product to be - removed from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 product_search_service.RemoveProductFromProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.RemoveProductFromProductSetRequest): - request = product_search_service.RemoveProductFromProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.remove_product_from_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_products_in_product_set(self, - request: Union[product_search_service.ListProductsInProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsInProductSetPager: - r"""Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.ListProductsInProductSetRequest, dict]): - The request object. Request message for the - `ListProductsInProductSet` method. - name (str): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p3beta1.services.product_search.pagers.ListProductsInProductSetPager: - Response message for the ListProductsInProductSet - method. - - 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([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 product_search_service.ListProductsInProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductsInProductSetRequest): - request = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set] - - # 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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListProductsInProductSetPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def import_product_sets(self, - request: Union[product_search_service.ImportProductSetsRequest, dict] = None, - *, - parent: str = None, - input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Args: - request (Union[google.cloud.vision_v1p3beta1.types.ImportProductSetsRequest, dict]): - The request object. Request message for the - `ImportProductSets` method. - parent (str): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - input_config (google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig): - Required. The input content for the - list of requests. - - This corresponds to the ``input_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.vision_v1p3beta1.types.ImportProductSetsResponse` - Response message for the ImportProductSets method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - """ - # 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, input_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 product_search_service.ImportProductSetsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ImportProductSetsRequest): - request = product_search_service.ImportProductSetsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if input_config is not None: - request.input_config = input_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.import_product_sets] - - # 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, - product_search_service.ImportProductSetsResponse, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ProductSearchClient", -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py deleted file mode 100644 index 1aa2e782..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/pagers.py +++ /dev/null @@ -1,506 +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, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator - -from google.cloud.vision_v1p3beta1.types import product_search_service - - -class ListProductSetsPager: - """A pager for iterating through ``list_product_sets`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``product_sets`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProductSets`` requests and continue to iterate - through the ``product_sets`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` - 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[..., product_search_service.ListProductSetsResponse], - request: product_search_service.ListProductSetsRequest, - response: product_search_service.ListProductSetsResponse, - *, - 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.vision_v1p3beta1.types.ListProductSetsRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListProductSetsResponse): - 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 = product_search_service.ListProductSetsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductSetsResponse]: - 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) -> Iterator[product_search_service.ProductSet]: - for page in self.pages: - yield from page.product_sets - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductSetsAsyncPager: - """A pager for iterating through ``list_product_sets`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``product_sets`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProductSets`` requests and continue to iterate - through the ``product_sets`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductSetsResponse` - 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[product_search_service.ListProductSetsResponse]], - request: product_search_service.ListProductSetsRequest, - response: product_search_service.ListProductSetsResponse, - *, - 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.vision_v1p3beta1.types.ListProductSetsRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListProductSetsResponse): - 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 = product_search_service.ListProductSetsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductSetsResponse]: - 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) -> AsyncIterator[product_search_service.ProductSet]: - async def async_generator(): - async for page in self.pages: - for response in page.product_sets: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` - 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[..., product_search_service.ListProductsResponse], - request: product_search_service.ListProductsRequest, - response: product_search_service.ListProductsResponse, - *, - 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.vision_v1p3beta1.types.ListProductsRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListProductsResponse): - 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 = product_search_service.ListProductsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductsResponse]: - 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) -> Iterator[product_search_service.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsAsyncPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsResponse` - 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[product_search_service.ListProductsResponse]], - request: product_search_service.ListProductsRequest, - response: product_search_service.ListProductsResponse, - *, - 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.vision_v1p3beta1.types.ListProductsRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListProductsResponse): - 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 = product_search_service.ListProductsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductsResponse]: - 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) -> AsyncIterator[product_search_service.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListReferenceImagesPager: - """A pager for iterating through ``list_reference_images`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` object, and - provides an ``__iter__`` method to iterate through its - ``reference_images`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListReferenceImages`` requests and continue to iterate - through the ``reference_images`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` - 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[..., product_search_service.ListReferenceImagesResponse], - request: product_search_service.ListReferenceImagesRequest, - response: product_search_service.ListReferenceImagesResponse, - *, - 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.vision_v1p3beta1.types.ListReferenceImagesRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse): - 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 = product_search_service.ListReferenceImagesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListReferenceImagesResponse]: - 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) -> Iterator[product_search_service.ReferenceImage]: - for page in self.pages: - yield from page.reference_images - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListReferenceImagesAsyncPager: - """A pager for iterating through ``list_reference_images`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``reference_images`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListReferenceImages`` requests and continue to iterate - through the ``reference_images`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse` - 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[product_search_service.ListReferenceImagesResponse]], - request: product_search_service.ListReferenceImagesRequest, - response: product_search_service.ListReferenceImagesResponse, - *, - 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.vision_v1p3beta1.types.ListReferenceImagesRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListReferenceImagesResponse): - 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 = product_search_service.ListReferenceImagesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListReferenceImagesResponse]: - 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) -> AsyncIterator[product_search_service.ReferenceImage]: - async def async_generator(): - async for page in self.pages: - for response in page.reference_images: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsInProductSetPager: - """A pager for iterating through ``list_products_in_product_set`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProductsInProductSet`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` - 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[..., product_search_service.ListProductsInProductSetResponse], - request: product_search_service.ListProductsInProductSetRequest, - response: product_search_service.ListProductsInProductSetResponse, - *, - 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.vision_v1p3beta1.types.ListProductsInProductSetRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse): - 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 = product_search_service.ListProductsInProductSetRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductsInProductSetResponse]: - 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) -> Iterator[product_search_service.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsInProductSetAsyncPager: - """A pager for iterating through ``list_products_in_product_set`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProductsInProductSet`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse` - 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[product_search_service.ListProductsInProductSetResponse]], - request: product_search_service.ListProductsInProductSetRequest, - response: product_search_service.ListProductsInProductSetResponse, - *, - 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.vision_v1p3beta1.types.ListProductsInProductSetRequest): - The initial request object. - response (google.cloud.vision_v1p3beta1.types.ListProductsInProductSetResponse): - 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 = product_search_service.ListProductsInProductSetRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductsInProductSetResponse]: - 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) -> AsyncIterator[product_search_service.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - 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/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/__init__.py deleted file mode 100644 index 22b20282..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/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 ProductSearchTransport -from .grpc import ProductSearchGrpcTransport -from .grpc_asyncio import ProductSearchGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ProductSearchTransport]] -_transport_registry['grpc'] = ProductSearchGrpcTransport -_transport_registry['grpc_asyncio'] = ProductSearchGrpcAsyncIOTransport - -__all__ = ( - 'ProductSearchTransport', - 'ProductSearchGrpcTransport', - 'ProductSearchGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py deleted file mode 100644 index 7caa2763..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/base.py +++ /dev/null @@ -1,534 +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.vision_v1p3beta1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-vision', - ).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 ProductSearchTransport(abc.ABC): - """Abstract transport class for ProductSearch.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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.create_product_set: gapic_v1.method.wrap_method( - self.create_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_product_sets: gapic_v1.method.wrap_method( - self.list_product_sets, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_product_set: gapic_v1.method.wrap_method( - self.get_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.update_product_set: gapic_v1.method.wrap_method( - self.update_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_product_set: gapic_v1.method.wrap_method( - self.delete_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.create_product: gapic_v1.method.wrap_method( - self.create_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_products: gapic_v1.method.wrap_method( - self.list_products, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_product: gapic_v1.method.wrap_method( - self.get_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.update_product: gapic_v1.method.wrap_method( - self.update_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_product: gapic_v1.method.wrap_method( - self.delete_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.create_reference_image: gapic_v1.method.wrap_method( - self.create_reference_image, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_reference_image: gapic_v1.method.wrap_method( - self.delete_reference_image, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_reference_images: gapic_v1.method.wrap_method( - self.list_reference_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_reference_image: gapic_v1.method.wrap_method( - self.get_reference_image, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.add_product_to_product_set: gapic_v1.method.wrap_method( - self.add_product_to_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.remove_product_from_product_set: gapic_v1.method.wrap_method( - self.remove_product_from_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_products_in_product_set: gapic_v1.method.wrap_method( - self.list_products_in_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.import_product_sets: gapic_v1.method.wrap_method( - self.import_product_sets, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - Union[ - product_search_service.ListProductSetsResponse, - Awaitable[product_search_service.ListProductSetsResponse] - ]]: - raise NotImplementedError() - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - Union[ - product_search_service.ListProductsResponse, - Awaitable[product_search_service.ListProductsResponse] - ]]: - raise NotImplementedError() - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - Union[ - product_search_service.ReferenceImage, - Awaitable[product_search_service.ReferenceImage] - ]]: - raise NotImplementedError() - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - Union[ - product_search_service.ListReferenceImagesResponse, - Awaitable[product_search_service.ListReferenceImagesResponse] - ]]: - raise NotImplementedError() - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - Union[ - product_search_service.ReferenceImage, - Awaitable[product_search_service.ReferenceImage] - ]]: - raise NotImplementedError() - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - Union[ - product_search_service.ListProductsInProductSetResponse, - Awaitable[product_search_service.ListProductsInProductSetResponse] - ]]: - raise NotImplementedError() - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ProductSearchTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py deleted file mode 100644 index 4daa61a6..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc.py +++ /dev/null @@ -1,880 +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.vision_v1p3beta1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO - - -class ProductSearchGrpcTransport(ProductSearchTransport): - """gRPC backend transport for ProductSearch. - - Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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 create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the create product set method over gRPC. - - Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Returns: - Callable[[~.CreateProductSetRequest], - ~.ProductSet]: - 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_product_set' not in self._stubs: - self._stubs['create_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProductSet', - request_serializer=product_search_service.CreateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['create_product_set'] - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - product_search_service.ListProductSetsResponse]: - r"""Return a callable for the list product sets method over gRPC. - - Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Returns: - Callable[[~.ListProductSetsRequest], - ~.ListProductSetsResponse]: - 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_product_sets' not in self._stubs: - self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductSets', - request_serializer=product_search_service.ListProductSetsRequest.serialize, - response_deserializer=product_search_service.ListProductSetsResponse.deserialize, - ) - return self._stubs['list_product_sets'] - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the get product set method over gRPC. - - Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.GetProductSetRequest], - ~.ProductSet]: - 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 'get_product_set' not in self._stubs: - self._stubs['get_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/GetProductSet', - request_serializer=product_search_service.GetProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['get_product_set'] - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the update product set method over gRPC. - - Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Returns: - Callable[[~.UpdateProductSetRequest], - ~.ProductSet]: - 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 'update_product_set' not in self._stubs: - self._stubs['update_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProductSet', - request_serializer=product_search_service.UpdateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['update_product_set'] - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product set method over gRPC. - - Permanently deletes a ProductSet. All Products and - ReferenceImages in the ProductSet will be deleted. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.DeleteProductSetRequest], - ~.Empty]: - 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_product_set' not in self._stubs: - self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProductSet', - request_serializer=product_search_service.DeleteProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_set'] - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - product_search_service.Product]: - r"""Return a callable for the create product method over gRPC. - - Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Returns: - Callable[[~.CreateProductRequest], - ~.Product]: - 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_product' not in self._stubs: - self._stubs['create_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProduct', - request_serializer=product_search_service.CreateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['create_product'] - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - product_search_service.ListProductsResponse]: - r"""Return a callable for the list products method over gRPC. - - Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsRequest], - ~.ListProductsResponse]: - 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_products' not in self._stubs: - self._stubs['list_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListProducts', - request_serializer=product_search_service.ListProductsRequest.serialize, - response_deserializer=product_search_service.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - product_search_service.Product]: - r"""Return a callable for the get product method over gRPC. - - Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns: - Callable[[~.GetProductRequest], - ~.Product]: - 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 'get_product' not in self._stubs: - self._stubs['get_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/GetProduct', - request_serializer=product_search_service.GetProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - product_search_service.Product]: - r"""Return a callable for the update product method over gRPC. - - Makes changes to a Product resource. Only display_name, - description and labels can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Returns: - Callable[[~.UpdateProductRequest], - ~.Product]: - 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 'update_product' not in self._stubs: - self._stubs['update_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProduct', - request_serializer=product_search_service.UpdateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['update_product'] - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product method over gRPC. - - Permanently deletes a product and its reference images. - - Metadata of the product and all its images will be deleted right - away, but search queries against ProductSets containing the - product may still work until all related caches are refreshed. - - Possible errors: - - - Returns NOT_FOUND if the product does not exist. - - Returns: - Callable[[~.DeleteProductRequest], - ~.Empty]: - 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_product' not in self._stubs: - self._stubs['delete_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProduct', - request_serializer=product_search_service.DeleteProductRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product'] - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - product_search_service.ReferenceImage]: - r"""Return a callable for the create reference image method over gRPC. - - Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Returns: - Callable[[~.CreateReferenceImageRequest], - ~.ReferenceImage]: - 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_reference_image' not in self._stubs: - self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/CreateReferenceImage', - request_serializer=product_search_service.CreateReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['create_reference_image'] - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete reference image method over gRPC. - - Permanently deletes a reference image. - - The image metadata will be deleted right away, but search - queries against ProductSets containing the image may still work - until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the reference image does not exist. - - Returns: - Callable[[~.DeleteReferenceImageRequest], - ~.Empty]: - 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_reference_image' not in self._stubs: - self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteReferenceImage', - request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_reference_image'] - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - product_search_service.ListReferenceImagesResponse]: - r"""Return a callable for the list reference images method over gRPC. - - Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Returns: - Callable[[~.ListReferenceImagesRequest], - ~.ListReferenceImagesResponse]: - 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_reference_images' not in self._stubs: - self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListReferenceImages', - request_serializer=product_search_service.ListReferenceImagesRequest.serialize, - response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, - ) - return self._stubs['list_reference_images'] - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - product_search_service.ReferenceImage]: - r"""Return a callable for the get reference image method over gRPC. - - Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Returns: - Callable[[~.GetReferenceImageRequest], - ~.ReferenceImage]: - 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 'get_reference_image' not in self._stubs: - self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/GetReferenceImage', - request_serializer=product_search_service.GetReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['get_reference_image'] - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the add product to product set method over gRPC. - - Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Returns: - Callable[[~.AddProductToProductSetRequest], - ~.Empty]: - 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 'add_product_to_product_set' not in self._stubs: - self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet', - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['add_product_to_product_set'] - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the remove product from product - set method over gRPC. - - Removes a Product from the specified ProductSet. - - Possible errors: - - - Returns NOT_FOUND If the Product is not found under the - ProductSet. - - Returns: - Callable[[~.RemoveProductFromProductSetRequest], - ~.Empty]: - 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 'remove_product_from_product_set' not in self._stubs: - self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet', - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['remove_product_from_product_set'] - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - product_search_service.ListProductsInProductSetResponse]: - r"""Return a callable for the list products in product set method over gRPC. - - Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsInProductSetRequest], - ~.ListProductsInProductSetResponse]: - 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_products_in_product_set' not in self._stubs: - self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet', - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, - ) - return self._stubs['list_products_in_product_set'] - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - operations_pb2.Operation]: - r"""Return a callable for the import product sets method over gRPC. - - Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Returns: - Callable[[~.ImportProductSetsRequest], - ~.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 'import_product_sets' not in self._stubs: - self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ImportProductSets', - request_serializer=product_search_service.ImportProductSetsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['import_product_sets'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ProductSearchGrpcTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py deleted file mode 100644 index 1516a119..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/services/product_search/transports/grpc_asyncio.py +++ /dev/null @@ -1,885 +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.vision_v1p3beta1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .grpc import ProductSearchGrpcTransport - - -class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): - """gRPC AsyncIO backend transport for ProductSearch. - - Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p3beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p3beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p3beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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 create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the create product set method over gRPC. - - Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Returns: - Callable[[~.CreateProductSetRequest], - Awaitable[~.ProductSet]]: - 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_product_set' not in self._stubs: - self._stubs['create_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProductSet', - request_serializer=product_search_service.CreateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['create_product_set'] - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - Awaitable[product_search_service.ListProductSetsResponse]]: - r"""Return a callable for the list product sets method over gRPC. - - Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Returns: - Callable[[~.ListProductSetsRequest], - Awaitable[~.ListProductSetsResponse]]: - 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_product_sets' not in self._stubs: - self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductSets', - request_serializer=product_search_service.ListProductSetsRequest.serialize, - response_deserializer=product_search_service.ListProductSetsResponse.deserialize, - ) - return self._stubs['list_product_sets'] - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the get product set method over gRPC. - - Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.GetProductSetRequest], - Awaitable[~.ProductSet]]: - 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 'get_product_set' not in self._stubs: - self._stubs['get_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/GetProductSet', - request_serializer=product_search_service.GetProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['get_product_set'] - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the update product set method over gRPC. - - Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Returns: - Callable[[~.UpdateProductSetRequest], - Awaitable[~.ProductSet]]: - 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 'update_product_set' not in self._stubs: - self._stubs['update_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProductSet', - request_serializer=product_search_service.UpdateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['update_product_set'] - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product set method over gRPC. - - Permanently deletes a ProductSet. All Products and - ReferenceImages in the ProductSet will be deleted. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.DeleteProductSetRequest], - Awaitable[~.Empty]]: - 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_product_set' not in self._stubs: - self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProductSet', - request_serializer=product_search_service.DeleteProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_set'] - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the create product method over gRPC. - - Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Returns: - Callable[[~.CreateProductRequest], - Awaitable[~.Product]]: - 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_product' not in self._stubs: - self._stubs['create_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/CreateProduct', - request_serializer=product_search_service.CreateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['create_product'] - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - Awaitable[product_search_service.ListProductsResponse]]: - r"""Return a callable for the list products method over gRPC. - - Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsRequest], - Awaitable[~.ListProductsResponse]]: - 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_products' not in self._stubs: - self._stubs['list_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListProducts', - request_serializer=product_search_service.ListProductsRequest.serialize, - response_deserializer=product_search_service.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the get product method over gRPC. - - Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns: - Callable[[~.GetProductRequest], - Awaitable[~.Product]]: - 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 'get_product' not in self._stubs: - self._stubs['get_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/GetProduct', - request_serializer=product_search_service.GetProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the update product method over gRPC. - - Makes changes to a Product resource. Only display_name, - description and labels can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Returns: - Callable[[~.UpdateProductRequest], - Awaitable[~.Product]]: - 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 'update_product' not in self._stubs: - self._stubs['update_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/UpdateProduct', - request_serializer=product_search_service.UpdateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['update_product'] - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product method over gRPC. - - Permanently deletes a product and its reference images. - - Metadata of the product and all its images will be deleted right - away, but search queries against ProductSets containing the - product may still work until all related caches are refreshed. - - Possible errors: - - - Returns NOT_FOUND if the product does not exist. - - Returns: - Callable[[~.DeleteProductRequest], - Awaitable[~.Empty]]: - 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_product' not in self._stubs: - self._stubs['delete_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteProduct', - request_serializer=product_search_service.DeleteProductRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product'] - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - Awaitable[product_search_service.ReferenceImage]]: - r"""Return a callable for the create reference image method over gRPC. - - Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Returns: - Callable[[~.CreateReferenceImageRequest], - Awaitable[~.ReferenceImage]]: - 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_reference_image' not in self._stubs: - self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/CreateReferenceImage', - request_serializer=product_search_service.CreateReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['create_reference_image'] - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete reference image method over gRPC. - - Permanently deletes a reference image. - - The image metadata will be deleted right away, but search - queries against ProductSets containing the image may still work - until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Possible errors: - - - Returns NOT_FOUND if the reference image does not exist. - - Returns: - Callable[[~.DeleteReferenceImageRequest], - Awaitable[~.Empty]]: - 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_reference_image' not in self._stubs: - self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/DeleteReferenceImage', - request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_reference_image'] - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - Awaitable[product_search_service.ListReferenceImagesResponse]]: - r"""Return a callable for the list reference images method over gRPC. - - Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Returns: - Callable[[~.ListReferenceImagesRequest], - Awaitable[~.ListReferenceImagesResponse]]: - 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_reference_images' not in self._stubs: - self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListReferenceImages', - request_serializer=product_search_service.ListReferenceImagesRequest.serialize, - response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, - ) - return self._stubs['list_reference_images'] - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - Awaitable[product_search_service.ReferenceImage]]: - r"""Return a callable for the get reference image method over gRPC. - - Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Returns: - Callable[[~.GetReferenceImageRequest], - Awaitable[~.ReferenceImage]]: - 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 'get_reference_image' not in self._stubs: - self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/GetReferenceImage', - request_serializer=product_search_service.GetReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['get_reference_image'] - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the add product to product set method over gRPC. - - Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Returns: - Callable[[~.AddProductToProductSetRequest], - Awaitable[~.Empty]]: - 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 'add_product_to_product_set' not in self._stubs: - self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/AddProductToProductSet', - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['add_product_to_product_set'] - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the remove product from product - set method over gRPC. - - Removes a Product from the specified ProductSet. - - Possible errors: - - - Returns NOT_FOUND If the Product is not found under the - ProductSet. - - Returns: - Callable[[~.RemoveProductFromProductSetRequest], - Awaitable[~.Empty]]: - 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 'remove_product_from_product_set' not in self._stubs: - self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/RemoveProductFromProductSet', - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['remove_product_from_product_set'] - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - Awaitable[product_search_service.ListProductsInProductSetResponse]]: - r"""Return a callable for the list products in product set method over gRPC. - - Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsInProductSetRequest], - Awaitable[~.ListProductsInProductSetResponse]]: - 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_products_in_product_set' not in self._stubs: - self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ListProductsInProductSet', - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, - ) - return self._stubs['list_products_in_product_set'] - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the import product sets method over gRPC. - - Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p3beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Returns: - Callable[[~.ImportProductSetsRequest], - 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 'import_product_sets' not in self._stubs: - self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p3beta1.ProductSearch/ImportProductSets', - request_serializer=product_search_service.ImportProductSetsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['import_product_sets'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ProductSearchGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py deleted file mode 100644 index 651a3e18..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/__init__.py +++ /dev/null @@ -1,190 +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 .geometry import ( - BoundingPoly, - NormalizedBoundingPoly, - NormalizedVertex, - Position, - Vertex, -) -from .image_annotator import ( - AnnotateFileResponse, - AnnotateImageRequest, - AnnotateImageResponse, - AsyncAnnotateFileRequest, - AsyncAnnotateFileResponse, - AsyncBatchAnnotateFilesRequest, - AsyncBatchAnnotateFilesResponse, - BatchAnnotateImagesRequest, - BatchAnnotateImagesResponse, - ColorInfo, - CropHint, - CropHintsAnnotation, - CropHintsParams, - DominantColorsAnnotation, - EntityAnnotation, - FaceAnnotation, - Feature, - GcsDestination, - GcsSource, - Image, - ImageAnnotationContext, - ImageContext, - ImageProperties, - ImageSource, - InputConfig, - LatLongRect, - LocalizedObjectAnnotation, - LocationInfo, - OperationMetadata, - OutputConfig, - Property, - SafeSearchAnnotation, - TextDetectionParams, - WebDetectionParams, - Likelihood, -) -from .product_search import ( - ProductSearchParams, - ProductSearchResults, - ProductSearchCategory, - ProductSearchResultsView, -) -from .product_search_service import ( - AddProductToProductSetRequest, - BatchOperationMetadata, - CreateProductRequest, - CreateProductSetRequest, - CreateReferenceImageRequest, - DeleteProductRequest, - DeleteProductSetRequest, - DeleteReferenceImageRequest, - GetProductRequest, - GetProductSetRequest, - GetReferenceImageRequest, - ImportProductSetsGcsSource, - ImportProductSetsInputConfig, - ImportProductSetsRequest, - ImportProductSetsResponse, - ListProductSetsRequest, - ListProductSetsResponse, - ListProductsInProductSetRequest, - ListProductsInProductSetResponse, - ListProductsRequest, - ListProductsResponse, - ListReferenceImagesRequest, - ListReferenceImagesResponse, - Product, - ProductSet, - ReferenceImage, - RemoveProductFromProductSetRequest, - UpdateProductRequest, - UpdateProductSetRequest, -) -from .text_annotation import ( - Block, - Page, - Paragraph, - Symbol, - TextAnnotation, - Word, -) -from .web_detection import ( - WebDetection, -) - -__all__ = ( - 'BoundingPoly', - 'NormalizedBoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocalizedObjectAnnotation', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'ProductSearchParams', - 'ProductSearchResults', - 'ProductSearchCategory', - 'ProductSearchResultsView', - 'AddProductToProductSetRequest', - 'BatchOperationMetadata', - 'CreateProductRequest', - 'CreateProductSetRequest', - 'CreateReferenceImageRequest', - 'DeleteProductRequest', - 'DeleteProductSetRequest', - 'DeleteReferenceImageRequest', - 'GetProductRequest', - 'GetProductSetRequest', - 'GetReferenceImageRequest', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ListProductsRequest', - 'ListProductsResponse', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'Product', - 'ProductSet', - 'ReferenceImage', - 'RemoveProductFromProductSetRequest', - 'UpdateProductRequest', - 'UpdateProductSetRequest', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.py deleted file mode 100644 index 1b4a7225..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/geometry.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. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p3beta1', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - 'NormalizedBoundingPoly', - 'Position', - }, -) - - -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.vision_v1p3beta1.types.Vertex]): - The bounding polygon vertices. - normalized_vertices (Sequence[google.cloud.vision_v1p3beta1.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', - ) - - -class NormalizedBoundingPoly(proto.Message): - r"""A normalized bounding polygon around a portion of an image. - - Attributes: - vertices (Sequence[google.cloud.vision_v1p3beta1.types.NormalizedVertex]): - Normalized vertices of the bounding polygon. - """ - - vertices = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='NormalizedVertex', - ) - - -class Position(proto.Message): - r"""A 3D position in the image, used primarily for Face detection - landmarks. A valid Position must have both x and y coordinates. - The position coordinates are in the same scale as the original - image. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate. - z (float): - Z coordinate (or depth). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - z = proto.Field( - proto.FLOAT, - number=3, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py deleted file mode 100644 index 45d94d86..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/image_annotator.py +++ /dev/null @@ -1,1327 +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.vision_v1p3beta1.types import geometry -from google.cloud.vision_v1p3beta1.types import product_search -from google.cloud.vision_v1p3beta1.types import text_annotation -from google.cloud.vision_v1p3beta1.types import web_detection as gcv_web_detection -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 latlng_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p3beta1', - manifest={ - 'Likelihood', - 'Feature', - 'ImageSource', - 'Image', - 'FaceAnnotation', - 'LocationInfo', - 'Property', - 'EntityAnnotation', - 'LocalizedObjectAnnotation', - 'SafeSearchAnnotation', - 'LatLongRect', - 'ColorInfo', - 'DominantColorsAnnotation', - 'ImageProperties', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'WebDetectionParams', - 'TextDetectionParams', - 'ImageContext', - 'AnnotateImageRequest', - 'ImageAnnotationContext', - 'AnnotateImageResponse', - 'AnnotateFileResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'InputConfig', - 'OutputConfig', - 'GcsSource', - 'GcsDestination', - 'OperationMetadata', - }, -) - - -class Likelihood(proto.Enum): - r"""A bucketized representation of likelihood, which is intended - to give clients highly stable results across model upgrades. - """ - UNKNOWN = 0 - VERY_UNLIKELY = 1 - UNLIKELY = 2 - POSSIBLE = 3 - LIKELY = 4 - VERY_LIKELY = 5 - - -class Feature(proto.Message): - r"""The type of Google Cloud Vision API detection to perform, and the - maximum number of results to return for that type. Multiple - ``Feature`` objects can be specified in the ``features`` list. - - Attributes: - type_ (google.cloud.vision_v1p3beta1.types.Feature.Type): - The feature type. - max_results (int): - Maximum number of results of this type. Does not apply to - ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or - ``CROP_HINTS``. - model (str): - Model to use for the feature. - Supported values: "builtin/stable" (the default - if unset) and "builtin/latest". - """ - class Type(proto.Enum): - r"""Type of Google Cloud Vision API feature to be extracted.""" - TYPE_UNSPECIFIED = 0 - FACE_DETECTION = 1 - LANDMARK_DETECTION = 2 - LOGO_DETECTION = 3 - LABEL_DETECTION = 4 - TEXT_DETECTION = 5 - DOCUMENT_TEXT_DETECTION = 11 - SAFE_SEARCH_DETECTION = 6 - IMAGE_PROPERTIES = 7 - CROP_HINTS = 9 - WEB_DETECTION = 10 - PRODUCT_SEARCH = 12 - OBJECT_LOCALIZATION = 19 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum=Type, - ) - max_results = proto.Field( - proto.INT32, - number=2, - ) - model = proto.Field( - proto.STRING, - number=3, - ) - - -class ImageSource(proto.Message): - r"""External image source (Google Cloud Storage or web URL image - location). - - Attributes: - gcs_image_uri (str): - **Use ``image_uri`` instead.** - - The 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. - image_uri (str): - The URI of the source image. Can be either: - - 1. A 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. - - 2. A publicly-accessible image HTTP/HTTPS URL. When fetching - images from HTTP/HTTPS URLs, Google cannot guarantee that - the request will be completed. Your request may fail if - the specified host denies the request (e.g. due to - request throttling or DOS prevention), or if Google - throttles requests to the site for abuse prevention. You - should not depend on externally-hosted images for - production applications. - - When both ``gcs_image_uri`` and ``image_uri`` are specified, - ``image_uri`` takes precedence. - """ - - gcs_image_uri = proto.Field( - proto.STRING, - number=1, - ) - image_uri = proto.Field( - proto.STRING, - number=2, - ) - - -class Image(proto.Message): - r"""Client image to perform Google Cloud Vision API tasks over. - - Attributes: - content (bytes): - Image content, represented as a stream of bytes. Note: As - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - source (google.cloud.vision_v1p3beta1.types.ImageSource): - Google Cloud Storage image location, or publicly-accessible - image URL. If both ``content`` and ``source`` are provided - for an image, ``content`` takes precedence and is used to - perform the image annotation request. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - source = proto.Field( - proto.MESSAGE, - number=2, - message='ImageSource', - ) - - -class FaceAnnotation(proto.Message): - r"""A face annotation object contains the results of face - detection. - - Attributes: - bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding polygon around the face. The coordinates of the - bounding box are in the original image's scale, as returned - in ``ImageParams``. The bounding box is computed to "frame" - the face in accordance with human expectations. It is based - on the landmarker results. Note that one or more x and/or y - coordinates may not be generated in the ``BoundingPoly`` - (the polygon will be unbounded) if only a partial face - appears in the image to be annotated. - fd_bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The ``fd_bounding_poly`` bounding polygon is tighter than - the ``boundingPoly``, and encloses only the skin part of the - face. Typically, it is used to eliminate the face from any - image analysis that detects the "amount of skin" visible in - an image. It is not based on the landmarker results, only on - the initial face detection, hence the fd (face detection) - prefix. - landmarks (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark]): - Detected face landmarks. - roll_angle (float): - Roll angle, which indicates the amount of - clockwise/anti-clockwise rotation of the face relative to - the image vertical about the axis perpendicular to the face. - Range [-180,180]. - pan_angle (float): - Yaw angle, which indicates the leftward/rightward angle that - the face is pointing relative to the vertical plane - perpendicular to the image. Range [-180,180]. - tilt_angle (float): - Pitch angle, which indicates the upwards/downwards angle - that the face is pointing relative to the image's horizontal - plane. Range [-180,180]. - detection_confidence (float): - Detection confidence. Range [0, 1]. - landmarking_confidence (float): - Face landmarking confidence. Range [0, 1]. - joy_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Joy likelihood. - sorrow_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Sorrow likelihood. - anger_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Anger likelihood. - surprise_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Surprise likelihood. - under_exposed_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Under-exposed likelihood. - blurred_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Blurred likelihood. - headwear_likelihood (google.cloud.vision_v1p3beta1.types.Likelihood): - Headwear likelihood. - """ - - class Landmark(proto.Message): - r"""A face-specific landmark (for example, a face feature). - - Attributes: - type_ (google.cloud.vision_v1p3beta1.types.FaceAnnotation.Landmark.Type): - Face landmark type. - position (google.cloud.vision_v1p3beta1.types.Position): - Face landmark position. - """ - class Type(proto.Enum): - r"""Face landmark (feature) type. Left and right are defined from the - vantage of the viewer of the image without considering mirror - projections typical of photos. So, ``LEFT_EYE``, typically, is the - person's right eye. - """ - UNKNOWN_LANDMARK = 0 - LEFT_EYE = 1 - RIGHT_EYE = 2 - LEFT_OF_LEFT_EYEBROW = 3 - RIGHT_OF_LEFT_EYEBROW = 4 - LEFT_OF_RIGHT_EYEBROW = 5 - RIGHT_OF_RIGHT_EYEBROW = 6 - MIDPOINT_BETWEEN_EYES = 7 - NOSE_TIP = 8 - UPPER_LIP = 9 - LOWER_LIP = 10 - MOUTH_LEFT = 11 - MOUTH_RIGHT = 12 - MOUTH_CENTER = 13 - NOSE_BOTTOM_RIGHT = 14 - NOSE_BOTTOM_LEFT = 15 - NOSE_BOTTOM_CENTER = 16 - LEFT_EYE_TOP_BOUNDARY = 17 - LEFT_EYE_RIGHT_CORNER = 18 - LEFT_EYE_BOTTOM_BOUNDARY = 19 - LEFT_EYE_LEFT_CORNER = 20 - RIGHT_EYE_TOP_BOUNDARY = 21 - RIGHT_EYE_RIGHT_CORNER = 22 - RIGHT_EYE_BOTTOM_BOUNDARY = 23 - RIGHT_EYE_LEFT_CORNER = 24 - LEFT_EYEBROW_UPPER_MIDPOINT = 25 - RIGHT_EYEBROW_UPPER_MIDPOINT = 26 - LEFT_EAR_TRAGION = 27 - RIGHT_EAR_TRAGION = 28 - LEFT_EYE_PUPIL = 29 - RIGHT_EYE_PUPIL = 30 - FOREHEAD_GLABELLA = 31 - CHIN_GNATHION = 32 - CHIN_LEFT_GONION = 33 - CHIN_RIGHT_GONION = 34 - - type_ = proto.Field( - proto.ENUM, - number=3, - enum='FaceAnnotation.Landmark.Type', - ) - position = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.Position, - ) - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - fd_bounding_poly = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - landmarks = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=Landmark, - ) - roll_angle = proto.Field( - proto.FLOAT, - number=4, - ) - pan_angle = proto.Field( - proto.FLOAT, - number=5, - ) - tilt_angle = proto.Field( - proto.FLOAT, - number=6, - ) - detection_confidence = proto.Field( - proto.FLOAT, - number=7, - ) - landmarking_confidence = proto.Field( - proto.FLOAT, - number=8, - ) - joy_likelihood = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - sorrow_likelihood = proto.Field( - proto.ENUM, - number=10, - enum='Likelihood', - ) - anger_likelihood = proto.Field( - proto.ENUM, - number=11, - enum='Likelihood', - ) - surprise_likelihood = proto.Field( - proto.ENUM, - number=12, - enum='Likelihood', - ) - under_exposed_likelihood = proto.Field( - proto.ENUM, - number=13, - enum='Likelihood', - ) - blurred_likelihood = proto.Field( - proto.ENUM, - number=14, - enum='Likelihood', - ) - headwear_likelihood = proto.Field( - proto.ENUM, - number=15, - enum='Likelihood', - ) - - -class LocationInfo(proto.Message): - r"""Detected entity location information. - - Attributes: - lat_lng (google.type.latlng_pb2.LatLng): - lat/long location coordinates. - """ - - lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - - -class Property(proto.Message): - r"""A ``Property`` consists of a user-supplied name/value pair. - - Attributes: - name (str): - Name of the property. - value (str): - Value of the property. - uint64_value (int): - Value of numeric properties. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - uint64_value = proto.Field( - proto.UINT64, - number=3, - ) - - -class EntityAnnotation(proto.Message): - r"""Set of detected entity features. - - Attributes: - mid (str): - Opaque entity ID. Some IDs may be available in `Google - Knowledge Graph Search - API `__. - locale (str): - The language code for the locale in which the entity textual - ``description`` is expressed. - description (str): - Entity textual description, expressed in its ``locale`` - language. - score (float): - Overall score of the result. Range [0, 1]. - confidence (float): - **Deprecated. Use ``score`` instead.** The accuracy of the - entity detection in an image. For example, for an image in - which the "Eiffel Tower" entity is detected, this field - represents the confidence that there is a tower in the query - image. Range [0, 1]. - topicality (float): - The relevancy of the ICA (Image Content Annotation) label to - the image. For example, the relevancy of "tower" is likely - higher to an image containing the detected "Eiffel Tower" - than to an image containing a detected distant towering - building, even though the confidence that there is a tower - in each image may be the same. Range [0, 1]. - bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): - Image region to which this entity belongs. Not produced for - ``LABEL_DETECTION`` features. - locations (Sequence[google.cloud.vision_v1p3beta1.types.LocationInfo]): - The location information for the detected entity. Multiple - ``LocationInfo`` elements can be present because one - location may indicate the location of the scene in the - image, and another location may indicate the location of the - place where the image was taken. Location information is - usually present for landmarks. - properties (Sequence[google.cloud.vision_v1p3beta1.types.Property]): - Some entities may have optional user-supplied ``Property`` - (name/value) fields, such a score or string that qualifies - the entity. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - locale = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - topicality = proto.Field( - proto.FLOAT, - number=6, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=7, - message=geometry.BoundingPoly, - ) - locations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='LocationInfo', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Property', - ) - - -class LocalizedObjectAnnotation(proto.Message): - r"""Set of detected objects with bounding boxes. - - Attributes: - mid (str): - Object ID that should align with - EntityAnnotation mid. - 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. - name (str): - Object name, expressed in its ``language_code`` language. - score (float): - Score of the result. Range [0, 1]. - bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): - Image region to which this object belongs. - This must be populated. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - name = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=5, - message=geometry.BoundingPoly, - ) - - -class SafeSearchAnnotation(proto.Message): - r"""Set of features pertaining to the image, computed by computer - vision methods over safe-search verticals (for example, adult, - spoof, medical, violence). - - Attributes: - adult (google.cloud.vision_v1p3beta1.types.Likelihood): - Represents the adult content likelihood for - the image. Adult content may contain elements - such as nudity, pornographic images or cartoons, - or sexual activities. - spoof (google.cloud.vision_v1p3beta1.types.Likelihood): - Spoof likelihood. The likelihood that an - modification was made to the image's canonical - version to make it appear funny or offensive. - medical (google.cloud.vision_v1p3beta1.types.Likelihood): - Likelihood that this is a medical image. - violence (google.cloud.vision_v1p3beta1.types.Likelihood): - Likelihood that this image contains violent - content. - racy (google.cloud.vision_v1p3beta1.types.Likelihood): - Likelihood that the request image contains - racy content. Racy content may include (but is - not limited to) skimpy or sheer clothing, - strategically covered nudity, lewd or - provocative poses, or close-ups of sensitive - body areas. - """ - - adult = proto.Field( - proto.ENUM, - number=1, - enum='Likelihood', - ) - spoof = proto.Field( - proto.ENUM, - number=2, - enum='Likelihood', - ) - medical = proto.Field( - proto.ENUM, - number=3, - enum='Likelihood', - ) - violence = proto.Field( - proto.ENUM, - number=4, - enum='Likelihood', - ) - racy = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - - -class LatLongRect(proto.Message): - r"""Rectangle determined by min and max ``LatLng`` pairs. - - Attributes: - min_lat_lng (google.type.latlng_pb2.LatLng): - Min lat/long pair. - max_lat_lng (google.type.latlng_pb2.LatLng): - Max lat/long pair. - """ - - min_lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - max_lat_lng = proto.Field( - proto.MESSAGE, - number=2, - message=latlng_pb2.LatLng, - ) - - -class ColorInfo(proto.Message): - r"""Color information consists of RGB channels, score, and the - fraction of the image that the color occupies in the image. - - Attributes: - color (google.type.color_pb2.Color): - RGB components of the color. - score (float): - Image-specific score for this color. Value in range [0, 1]. - pixel_fraction (float): - The fraction of pixels the color occupies in the image. - Value in range [0, 1]. - """ - - color = proto.Field( - proto.MESSAGE, - number=1, - message=color_pb2.Color, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - pixel_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class DominantColorsAnnotation(proto.Message): - r"""Set of dominant colors and their corresponding scores. - - Attributes: - colors (Sequence[google.cloud.vision_v1p3beta1.types.ColorInfo]): - RGB color values with their score and pixel - fraction. - """ - - colors = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ColorInfo', - ) - - -class ImageProperties(proto.Message): - r"""Stores image properties, such as dominant colors. - - Attributes: - dominant_colors (google.cloud.vision_v1p3beta1.types.DominantColorsAnnotation): - If present, dominant colors completed - successfully. - """ - - dominant_colors = proto.Field( - proto.MESSAGE, - number=1, - message='DominantColorsAnnotation', - ) - - -class CropHint(proto.Message): - r"""Single crop hint that is used to generate a new crop when - serving an image. - - Attributes: - bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding polygon for the crop region. The coordinates of - the bounding box are in the original image's scale, as - returned in ``ImageParams``. - confidence (float): - Confidence of this being a salient region. Range [0, 1]. - importance_fraction (float): - Fraction of importance of this salient region - with respect to the original image. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - importance_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class CropHintsAnnotation(proto.Message): - r"""Set of crop hints that are used to generate new crops when - serving images. - - Attributes: - crop_hints (Sequence[google.cloud.vision_v1p3beta1.types.CropHint]): - Crop hint results. - """ - - crop_hints = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='CropHint', - ) - - -class CropHintsParams(proto.Message): - r"""Parameters for crop hints annotation request. - - Attributes: - aspect_ratios (Sequence[float]): - Aspect ratios in floats, representing the - ratio of the width to the height of the image. - For example, if the desired aspect ratio is 4/3, - the corresponding float value should be 1.33333. - If not specified, the best possible crop is - returned. The number of provided aspect ratios - is limited to a maximum of 16; any aspect ratios - provided after the 16th are ignored. - """ - - aspect_ratios = proto.RepeatedField( - proto.FLOAT, - number=1, - ) - - -class WebDetectionParams(proto.Message): - r"""Parameters for web detection request. - - Attributes: - include_geo_results (bool): - Whether to include results derived from the - geo information in the image. - """ - - include_geo_results = proto.Field( - proto.BOOL, - number=2, - ) - - -class TextDetectionParams(proto.Message): - r"""Parameters for text detections. This is used to control - TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. - - Attributes: - enable_text_detection_confidence_score (bool): - By default, Cloud Vision API only includes confidence score - for DOCUMENT_TEXT_DETECTION result. Set the flag to true to - include confidence score for TEXT_DETECTION as well. - """ - - enable_text_detection_confidence_score = proto.Field( - proto.BOOL, - number=9, - ) - - -class ImageContext(proto.Message): - r"""Image context and/or feature-specific parameters. - - Attributes: - lat_long_rect (google.cloud.vision_v1p3beta1.types.LatLongRect): - Not used. - language_hints (Sequence[str]): - List of languages to use for TEXT_DETECTION. 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). - Text detection returns an error if one or more of the - specified languages is not one of the `supported - languages `__. - crop_hints_params (google.cloud.vision_v1p3beta1.types.CropHintsParams): - Parameters for crop hints annotation request. - product_search_params (google.cloud.vision_v1p3beta1.types.ProductSearchParams): - Parameters for product search. - web_detection_params (google.cloud.vision_v1p3beta1.types.WebDetectionParams): - Parameters for web detection. - text_detection_params (google.cloud.vision_v1p3beta1.types.TextDetectionParams): - Parameters for text detection and document - text detection. - """ - - lat_long_rect = proto.Field( - proto.MESSAGE, - number=1, - message='LatLongRect', - ) - language_hints = proto.RepeatedField( - proto.STRING, - number=2, - ) - crop_hints_params = proto.Field( - proto.MESSAGE, - number=4, - message='CropHintsParams', - ) - product_search_params = proto.Field( - proto.MESSAGE, - number=5, - message=product_search.ProductSearchParams, - ) - web_detection_params = proto.Field( - proto.MESSAGE, - number=6, - message='WebDetectionParams', - ) - text_detection_params = proto.Field( - proto.MESSAGE, - number=12, - message='TextDetectionParams', - ) - - -class AnnotateImageRequest(proto.Message): - r"""Request for performing Google Cloud Vision API tasks over a - user-provided image, with user-requested features. - - Attributes: - image (google.cloud.vision_v1p3beta1.types.Image): - The image to be processed. - features (Sequence[google.cloud.vision_v1p3beta1.types.Feature]): - Requested features. - image_context (google.cloud.vision_v1p3beta1.types.ImageContext): - Additional context that may accompany the - image. - """ - - image = proto.Field( - proto.MESSAGE, - number=1, - message='Image', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - - -class ImageAnnotationContext(proto.Message): - r"""If an image was produced from a file (e.g. a PDF), this - message gives information about the source of that image. - - Attributes: - uri (str): - The URI of the file used to produce the - image. - page_number (int): - If the file was a PDF or TIFF, this field - gives the page number within the file used to - produce the image. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - page_number = proto.Field( - proto.INT32, - number=2, - ) - - -class AnnotateImageResponse(proto.Message): - r"""Response to an image annotation request. - - Attributes: - face_annotations (Sequence[google.cloud.vision_v1p3beta1.types.FaceAnnotation]): - If present, face detection has completed - successfully. - landmark_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): - If present, landmark detection has completed - successfully. - logo_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): - If present, logo detection has completed - successfully. - label_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): - If present, label detection has completed - successfully. - localized_object_annotations (Sequence[google.cloud.vision_v1p3beta1.types.LocalizedObjectAnnotation]): - If present, localized object detection has - completed successfully. This will be sorted - descending by confidence score. - text_annotations (Sequence[google.cloud.vision_v1p3beta1.types.EntityAnnotation]): - If present, text (OCR) detection has - completed successfully. - full_text_annotation (google.cloud.vision_v1p3beta1.types.TextAnnotation): - If present, text (OCR) detection or document - (OCR) text detection has completed successfully. - This annotation provides the structural - hierarchy for the OCR detected text. - safe_search_annotation (google.cloud.vision_v1p3beta1.types.SafeSearchAnnotation): - If present, safe-search annotation has - completed successfully. - image_properties_annotation (google.cloud.vision_v1p3beta1.types.ImageProperties): - If present, image properties were extracted - successfully. - crop_hints_annotation (google.cloud.vision_v1p3beta1.types.CropHintsAnnotation): - If present, crop hints have completed - successfully. - web_detection (google.cloud.vision_v1p3beta1.types.WebDetection): - If present, web detection has completed - successfully. - product_search_results (google.cloud.vision_v1p3beta1.types.ProductSearchResults): - If present, product search has completed - successfully. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the operation. Note - that filled-in image annotations are guaranteed to be - correct, even when ``error`` is set. - context (google.cloud.vision_v1p3beta1.types.ImageAnnotationContext): - If present, contextual information is needed - to understand where this image comes from. - """ - - face_annotations = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='FaceAnnotation', - ) - landmark_annotations = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='EntityAnnotation', - ) - logo_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='EntityAnnotation', - ) - label_annotations = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='EntityAnnotation', - ) - localized_object_annotations = proto.RepeatedField( - proto.MESSAGE, - number=22, - message='LocalizedObjectAnnotation', - ) - text_annotations = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='EntityAnnotation', - ) - full_text_annotation = proto.Field( - proto.MESSAGE, - number=12, - message=text_annotation.TextAnnotation, - ) - safe_search_annotation = proto.Field( - proto.MESSAGE, - number=6, - message='SafeSearchAnnotation', - ) - image_properties_annotation = proto.Field( - proto.MESSAGE, - number=8, - message='ImageProperties', - ) - crop_hints_annotation = proto.Field( - proto.MESSAGE, - number=11, - message='CropHintsAnnotation', - ) - web_detection = proto.Field( - proto.MESSAGE, - number=13, - message=gcv_web_detection.WebDetection, - ) - product_search_results = proto.Field( - proto.MESSAGE, - number=14, - message=product_search.ProductSearchResults, - ) - error = proto.Field( - proto.MESSAGE, - number=9, - message=status_pb2.Status, - ) - context = proto.Field( - proto.MESSAGE, - number=21, - message='ImageAnnotationContext', - ) - - -class AnnotateFileResponse(proto.Message): - r"""Response to a single file annotation request. A file may - contain one or more images, which individually have their own - responses. - - Attributes: - input_config (google.cloud.vision_v1p3beta1.types.InputConfig): - Information about the file for which this - response is generated. - responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): - Individual responses to images found within - the file. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - responses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AnnotateImageResponse', - ) - - -class BatchAnnotateImagesRequest(proto.Message): - r"""Multiple image annotation requests are batched into a single - service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageRequest]): - Individual image annotation requests for this - batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - - -class BatchAnnotateImagesResponse(proto.Message): - r"""Response to a batch image annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p3beta1.types.AnnotateImageResponse]): - Individual responses to image annotation - requests within the batch. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageResponse', - ) - - -class AsyncAnnotateFileRequest(proto.Message): - r"""An offline file annotation request. - - Attributes: - input_config (google.cloud.vision_v1p3beta1.types.InputConfig): - Required. Information about the input file. - features (Sequence[google.cloud.vision_v1p3beta1.types.Feature]): - Required. Requested features. - image_context (google.cloud.vision_v1p3beta1.types.ImageContext): - Additional context that may accompany the - image(s) in the file. - output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): - Required. The desired output location and - metadata (e.g. format). - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - output_config = proto.Field( - proto.MESSAGE, - number=4, - message='OutputConfig', - ) - - -class AsyncAnnotateFileResponse(proto.Message): - r"""The response for a single offline file annotation request. - - Attributes: - output_config (google.cloud.vision_v1p3beta1.types.OutputConfig): - The output location and metadata from - AsyncAnnotateFileRequest. - """ - - output_config = proto.Field( - proto.MESSAGE, - number=1, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateFilesRequest(proto.Message): - r"""Multiple async file annotation requests are batched into a - single service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileRequest]): - Required. Individual async file annotation - requests for this batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileRequest', - ) - - -class AsyncBatchAnnotateFilesResponse(proto.Message): - r"""Response to an async batch file annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p3beta1.types.AsyncAnnotateFileResponse]): - The list of file annotation responses, one - for each request in - AsyncBatchAnnotateFilesRequest. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileResponse', - ) - - -class InputConfig(proto.Message): - r"""The desired input location and metadata. - - Attributes: - gcs_source (google.cloud.vision_v1p3beta1.types.GcsSource): - The Google Cloud Storage location to read the - input from. - mime_type (str): - The type of the file. Currently only - "application/pdf" and "image/tiff" are - supported. Wildcards are not supported. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - message='GcsSource', - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class OutputConfig(proto.Message): - r"""The desired output location and metadata. - - Attributes: - gcs_destination (google.cloud.vision_v1p3beta1.types.GcsDestination): - The Google Cloud Storage location to write - the output(s) to. - batch_size (int): - The max number of response protos to put into each output - JSON file 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 response - protos will be generated. If ``batch_size`` = 20, then 5 - json files each containing 20 response protos will be - written under the prefix ``gcs_destination``.\ ``uri``. - - Currently, batch_size only applies to GcsDestination, with - potential future support for other output configurations. - """ - - gcs_destination = proto.Field( - proto.MESSAGE, - number=1, - message='GcsDestination', - ) - batch_size = proto.Field( - proto.INT32, - number=2, - ) - - -class GcsSource(proto.Message): - r"""The Google Cloud Storage location where the input will be - read from. - - Attributes: - uri (str): - Google Cloud Storage URI for the input file. - This must only be a Google Cloud Storage object. - Wildcards are not currently supported. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class GcsDestination(proto.Message): - r"""The Google Cloud Storage location where the output will be - written to. - - Attributes: - uri (str): - Google Cloud Storage URI where the results will be stored. - Results will be in JSON format and preceded by its - corresponding input URI. This field can either represent a - single file, or a prefix for multiple outputs. Prefixes must - end in a ``/``. - - Examples: - - - File: gs://bucket-name/filename.json - - Prefix: gs://bucket-name/prefix/here/ - - File: gs://bucket-name/prefix/here - - If multiple outputs, each response is still - AnnotateFileResponse, each of which contains some subset of - the full list of AnnotateImageResponse. Multiple outputs can - happen if, for example, the output JSON is too large and - overflows into multiple sharded files. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class OperationMetadata(proto.Message): - r"""Contains metadata for the BatchAnnotateImages operation. - - Attributes: - state (google.cloud.vision_v1p3beta1.types.OperationMetadata.State): - Current state of the batch operation. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was received. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the operation result was last - updated. - """ - class State(proto.Enum): - r"""Batch operation states.""" - STATE_UNSPECIFIED = 0 - CREATED = 1 - RUNNING = 2 - DONE = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - create_time = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=6, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py deleted file mode 100644 index 03097093..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search.py +++ /dev/null @@ -1,249 +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.vision_v1p3beta1.types import geometry -from google.cloud.vision_v1p3beta1.types import product_search_service -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p3beta1', - manifest={ - 'ProductSearchCategory', - 'ProductSearchResultsView', - 'ProductSearchParams', - 'ProductSearchResults', - }, -) - - -class ProductSearchCategory(proto.Enum): - r"""Supported product search categories.""" - PRODUCT_SEARCH_CATEGORY_UNSPECIFIED = 0 - SHOES = 1 - BAGS = 2 - - -class ProductSearchResultsView(proto.Enum): - r"""Specifies the fields to include in product search results.""" - BASIC = 0 - FULL = 1 - - -class ProductSearchParams(proto.Message): - r"""Parameters for a product search request. - - Attributes: - catalog_name (str): - The resource name of the catalog to search. - - Format is: ``productSearch/catalogs/CATALOG_NAME``. - category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): - The category to search in. Optional. It is inferred by the - system if it is not specified. [Deprecated] Use - ``product_category``. - product_category (str): - The product category to search in. Optional. It is inferred - by the system if it is not specified. Supported values are - ``bag``, ``shoe``, ``sunglasses``, ``dress``, ``outerwear``, - ``skirt``, ``top``, ``shorts``, and ``pants``. - normalized_bounding_poly (google.cloud.vision_v1p3beta1.types.NormalizedBoundingPoly): - The bounding polygon around the area of interest in the - image. Optional. If it is not specified, system discretion - will be applied. [Deprecated] Use ``bounding_poly``. - bounding_poly (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding polygon around the area of - interest in the image. Optional. If it is not - specified, system discretion will be applied. - view (google.cloud.vision_v1p3beta1.types.ProductSearchResultsView): - Specifies the verbosity of the product search results. - Optional. Defaults to ``BASIC``. - product_set (str): - The resource name of a - [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] to be - searched for similar images. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. - product_categories (Sequence[str]): - The list of product categories to search in. - Currently, we only consider the first category, - and either "homegoods" or "apparel" should be - specified. - filter (str): - The filtering expression. This can be used to - restrict search results based on Product labels. - We currently support an AND of OR of key-value - expressions, where each expression within an OR - must have the same key. - For example, "(color = red OR color = blue) AND - brand = Google" is acceptable, but not "(color = - red OR brand = Google)" or "color: red". - """ - - catalog_name = proto.Field( - proto.STRING, - number=1, - ) - category = proto.Field( - proto.ENUM, - number=2, - enum='ProductSearchCategory', - ) - product_category = proto.Field( - proto.STRING, - number=5, - ) - normalized_bounding_poly = proto.Field( - proto.MESSAGE, - number=3, - message=geometry.NormalizedBoundingPoly, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=9, - message=geometry.BoundingPoly, - ) - view = proto.Field( - proto.ENUM, - number=4, - enum='ProductSearchResultsView', - ) - product_set = proto.Field( - proto.STRING, - number=6, - ) - product_categories = proto.RepeatedField( - proto.STRING, - number=7, - ) - filter = proto.Field( - proto.STRING, - number=8, - ) - - -class ProductSearchResults(proto.Message): - r"""Results for a product search request. - - Attributes: - category (google.cloud.vision_v1p3beta1.types.ProductSearchCategory): - Product category. [Deprecated] Use ``product_category``. - product_category (str): - Product category. Supported values are ``bag`` and ``shoe``. - [Deprecated] ``product_category`` is provided in each - Product. - index_time (google.protobuf.timestamp_pb2.Timestamp): - Timestamp of the index which provided these - results. Changes made after this time are not - reflected in the current results. - products (Sequence[google.cloud.vision_v1p3beta1.types.ProductSearchResults.ProductInfo]): - List of detected products. - results (Sequence[google.cloud.vision_v1p3beta1.types.ProductSearchResults.Result]): - List of results, one for each product match. - """ - - class ProductInfo(proto.Message): - r"""Information about a product. - - Attributes: - product_id (str): - Product ID. - image_uri (str): - The URI of the image which matched the query image. - - This field is returned only if ``view`` is set to ``FULL`` - in the request. - score (float): - A confidence level on the match, ranging from 0 (no - confidence) to 1 (full confidence). - - This field is returned only if ``view`` is set to ``FULL`` - in the request. - """ - - product_id = proto.Field( - proto.STRING, - number=1, - ) - image_uri = proto.Field( - proto.STRING, - number=2, - ) - score = proto.Field( - proto.FLOAT, - number=3, - ) - - class Result(proto.Message): - r"""Information about a product. - - Attributes: - product (google.cloud.vision_v1p3beta1.types.Product): - The Product. - score (float): - A confidence level on the match, ranging from 0 (no - confidence) to 1 (full confidence). - - This field is returned only if ``view`` is set to ``FULL`` - in the request. - image (str): - The resource name of the image from the - product that is the closest match to the query. - """ - - product = proto.Field( - proto.MESSAGE, - number=1, - message=product_search_service.Product, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - image = proto.Field( - proto.STRING, - number=3, - ) - - category = proto.Field( - proto.ENUM, - number=1, - enum='ProductSearchCategory', - ) - product_category = proto.Field( - proto.STRING, - number=4, - ) - index_time = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - products = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=ProductInfo, - ) - results = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=Result, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py deleted file mode 100644 index c3b3d8be..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/product_search_service.py +++ /dev/null @@ -1,998 +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.vision_v1p3beta1.types import geometry -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p3beta1', - manifest={ - 'Product', - 'ProductSet', - 'ReferenceImage', - 'CreateProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'GetProductRequest', - 'UpdateProductRequest', - 'DeleteProductRequest', - 'CreateProductSetRequest', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'GetProductSetRequest', - 'UpdateProductSetRequest', - 'DeleteProductSetRequest', - 'CreateReferenceImageRequest', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'GetReferenceImageRequest', - 'DeleteReferenceImageRequest', - 'AddProductToProductSetRequest', - 'RemoveProductFromProductSetRequest', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'BatchOperationMetadata', - }, -) - - -class Product(proto.Message): - r"""A Product contains ReferenceImages. - - Attributes: - name (str): - The resource name of the product. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This field is ignored when creating a product. - display_name (str): - The user-provided name for this Product. Must - not be empty. Must be at most 4096 characters - long. - description (str): - User-provided metadata to be stored with this - product. Must be at most 4096 characters long. - product_category (str): - Immutable. The category for the product - identified by the reference image. This should - be either "homegoods-v2", "apparel-v2", or - "toys-v2". The legacy categories "homegoods", - "apparel", and "toys" are still supported, but - these should not be used for new products. - product_labels (Sequence[google.cloud.vision_v1p3beta1.types.Product.KeyValue]): - Key-value pairs that can be attached to a product. At query - time, constraints can be specified based on the - product_labels. - - Note that integer values can be provided as strings, e.g. - "1199". Only strings with integer values can match a - range-based restriction which is to be supported soon. - - Multiple values can be assigned to the same key. One product - may have up to 100 product_labels. - """ - - class KeyValue(proto.Message): - r"""A product label represented as a key-value pair. - - Attributes: - key (str): - The key of the label attached to the product. - Cannot be empty and cannot exceed 128 bytes. - value (str): - The value of the label attached to the - product. Cannot be empty and cannot exceed 128 - bytes. - """ - - key = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - product_category = proto.Field( - proto.STRING, - number=4, - ) - product_labels = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=KeyValue, - ) - - -class ProductSet(proto.Message): - r"""A ProductSet contains Products. A ProductSet can contain a - maximum of 1 million reference images. If the limit is exceeded, - periodic indexing will fail. - - Attributes: - name (str): - The resource name of the ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. - - This field is ignored when creating a ProductSet. - display_name (str): - The user-provided name for this ProductSet. - Must not be empty. Must be at most 4096 - characters long. - index_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which this - ProductSet was last indexed. Query results will - reflect all updates before this time. If this - ProductSet has never been indexed, this field is - 0. - - This field is ignored when creating a - ProductSet. - index_error (google.rpc.status_pb2.Status): - Output only. If there was an error with - indexing the product set, the field is - populated. - This field is ignored when creating a - ProductSet. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - index_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - index_error = proto.Field( - proto.MESSAGE, - number=4, - message=status_pb2.Status, - ) - - -class ReferenceImage(proto.Message): - r"""A ``ReferenceImage`` represents a product image and its associated - metadata, such as bounding boxes. - - Attributes: - name (str): - The resource name of the reference image. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - This field is ignored when creating a reference image. - uri (str): - Required. The Google Cloud Storage URI of the reference - image. - - The URI must start with ``gs://``. - bounding_polys (Sequence[google.cloud.vision_v1p3beta1.types.BoundingPoly]): - Optional. Bounding polygons around the areas - of interest in the reference image. If this - field is empty, the system will try to detect - regions of interest. At most 10 bounding - polygons will be used. - The provided shape is converted into a non- - rotated rectangle. Once converted, the small - edge of the rectangle must be greater than or - equal to 300 pixels. The aspect ratio must be - 1:4 or less (i.e. 1:3 is ok; 1:5 is not). - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - uri = proto.Field( - proto.STRING, - number=2, - ) - bounding_polys = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=geometry.BoundingPoly, - ) - - -class CreateProductRequest(proto.Message): - r"""Request message for the ``CreateProduct`` method. - - Attributes: - parent (str): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product (google.cloud.vision_v1p3beta1.types.Product): - Required. The product to create. - product_id (str): - A user-supplied resource id for this Product. If set, the - server will attempt to use this value as the resource id. If - it is already in use, an error is returned with code - ALREADY_EXISTS. Must be at most 128 characters long. It - cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.MESSAGE, - number=2, - message='Product', - ) - product_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsRequest(proto.Message): - r"""Request message for the ``ListProducts`` method. - - Attributes: - parent (str): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsResponse(proto.Message): - r"""Response message for the ``ListProducts`` method. - - Attributes: - products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): - List of products. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - products = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class GetProductRequest(proto.Message): - r"""Request message for the ``GetProduct`` method. - - Attributes: - name (str): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateProductRequest(proto.Message): - r"""Request message for the ``UpdateProduct`` method. - - Attributes: - product (google.cloud.vision_v1p3beta1.types.Product): - Required. The Product resource which replaces - the one on the server. product.name is - immutable. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that specifies - which fields to update. If update_mask isn't specified, all - mutable fields are to be updated. Valid mask paths include - ``product_labels``, ``display_name``, and ``description``. - """ - - product = proto.Field( - proto.MESSAGE, - number=1, - message='Product', - ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteProductRequest(proto.Message): - r"""Request message for the ``DeleteProduct`` method. - - Attributes: - name (str): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateProductSetRequest(proto.Message): - r"""Request message for the ``CreateProductSet`` method. - - Attributes: - parent (str): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product_set (google.cloud.vision_v1p3beta1.types.ProductSet): - Required. The ProductSet to create. - product_set_id (str): - A user-supplied resource id for this ProductSet. If set, the - server will attempt to use this value as the resource id. If - it is already in use, an error is returned with code - ALREADY_EXISTS. Must be at most 128 characters long. It - cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - product_set = proto.Field( - proto.MESSAGE, - number=2, - message='ProductSet', - ) - product_set_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductSetsRequest(proto.Message): - r"""Request message for the ``ListProductSets`` method. - - Attributes: - parent (str): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductSetsResponse(proto.Message): - r"""Response message for the ``ListProductSets`` method. - - Attributes: - product_sets (Sequence[google.cloud.vision_v1p3beta1.types.ProductSet]): - List of ProductSets. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - product_sets = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ProductSet', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class GetProductSetRequest(proto.Message): - r"""Request message for the ``GetProductSet`` method. - - Attributes: - name (str): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateProductSetRequest(proto.Message): - r"""Request message for the ``UpdateProductSet`` method. - - Attributes: - product_set (google.cloud.vision_v1p3beta1.types.ProductSet): - Required. The ProductSet resource which - replaces the one on the server. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that specifies - which fields to update. If update_mask isn't specified, all - mutable fields are to be updated. Valid mask path is - ``display_name``. - """ - - product_set = proto.Field( - proto.MESSAGE, - number=1, - message='ProductSet', - ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteProductSetRequest(proto.Message): - r"""Request message for the ``DeleteProductSet`` method. - - Attributes: - name (str): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateReferenceImageRequest(proto.Message): - r"""Request message for the ``CreateReferenceImage`` method. - - Attributes: - parent (str): - Required. Resource name of the product in which to create - the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - reference_image (google.cloud.vision_v1p3beta1.types.ReferenceImage): - Required. The reference image to create. - If an image ID is specified, it is ignored. - reference_image_id (str): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value as - the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - reference_image = proto.Field( - proto.MESSAGE, - number=2, - message='ReferenceImage', - ) - reference_image_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListReferenceImagesRequest(proto.Message): - r"""Request message for the ``ListReferenceImages`` method. - - Attributes: - parent (str): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - A token identifying a page of results to be returned. This - is the value of ``nextPageToken`` returned in a previous - reference image list request. - - Defaults to the first page if not specified. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListReferenceImagesResponse(proto.Message): - r"""Response message for the ``ListReferenceImages`` method. - - Attributes: - reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): - The list of reference images. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - next_page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - @property - def raw_page(self): - return self - - reference_images = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ReferenceImage', - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - next_page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class GetReferenceImageRequest(proto.Message): - r"""Request message for the ``GetReferenceImage`` method. - - Attributes: - name (str): - Required. The resource name of the ReferenceImage to get. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class DeleteReferenceImageRequest(proto.Message): - r"""Request message for the ``DeleteReferenceImage`` method. - - Attributes: - name (str): - Required. The resource name of the reference image to - delete. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class AddProductToProductSetRequest(proto.Message): - r"""Request message for the ``AddProductToProductSet`` method. - - Attributes: - name (str): - Required. The resource name for the ProductSet to modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - product (str): - Required. The resource name for the Product to be added to - this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.STRING, - number=2, - ) - - -class RemoveProductFromProductSetRequest(proto.Message): - r"""Request message for the ``RemoveProductFromProductSet`` method. - - Attributes: - name (str): - Required. The resource name for the ProductSet to modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - product (str): - Required. The resource name for the Product to be removed - from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.STRING, - number=2, - ) - - -class ListProductsInProductSetRequest(proto.Message): - r"""Request message for the ``ListProductsInProductSet`` method. - - Attributes: - name (str): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsInProductSetResponse(proto.Message): - r"""Response message for the ``ListProductsInProductSet`` method. - - Attributes: - products (Sequence[google.cloud.vision_v1p3beta1.types.Product]): - The list of Products. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - products = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class ImportProductSetsGcsSource(proto.Message): - r"""The Google Cloud Storage location for a csv file which - preserves a list of ImportProductSetRequests in each line. - - Attributes: - csv_file_uri (str): - The Google Cloud Storage URI of the input csv file. - - The URI must start with ``gs://``. - - The format of the input csv file should be one image per - line. In each line, there are 6 columns. - - 1. image_uri 2, image_id - 2. product_set_id - 3. product_id 5, product_category 6, product_display_name 7, - labels - 4. bounding_poly - - Columns 1, 3, 4, and 5 are required, other columns are - optional. A new ProductSet/Product with the same id will be - created on the fly if the ProductSet/Product specified by - product_set_id/product_id does not exist. - - The image_id field is optional but has to be unique if - provided. If it is empty, we will automatically assign an - unique id to the image. - - The product_display_name field is optional. If it is empty, - a space (" ") is used as the place holder for the product - display_name, which can be updated later through the - realtime API. - - If the Product with product_id already exists, the fields - product_display_name, product_category and labels are - ignored. - - If a Product doesn't exist and needs to be created on the - fly, the product_display_name field refers to - [Product.display_name][google.cloud.vision.v1p3beta1.Product.display_name], - the product_category field refers to - [Product.product_category][google.cloud.vision.v1p3beta1.Product.product_category], - and the labels field refers to [Product.labels][]. - - Labels (optional) should be a line containing a list of - comma-separated key-value pairs, with the format - "key_1=value_1,key_2=value_2,...,key_n=value_n". - - The bounding_poly (optional) field is used to identify one - region of interest from the image in the same manner as - CreateReferenceImage. If no bounding_poly is specified, the - system will try to detect regions of interest automatically. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 20MP). - - Also note that at most one bounding_poly is allowed per - line. If the image contains multiple regions of interest, - the csv should contain one line per region of interest. - - The bounding_poly column should contain an even number of - comma-separated numbers, with the format - "p1_x,p1_y,p2_x,p2_y,...,pn_x,pn_y". Nonnegative integers - should be used for absolute bounding polygons, and float - values in [0, 1] should be used for normalized bounding - polygons. - """ - - csv_file_uri = proto.Field( - proto.STRING, - number=1, - ) - - -class ImportProductSetsInputConfig(proto.Message): - r"""The input content for the ``ImportProductSets`` method. - - Attributes: - gcs_source (google.cloud.vision_v1p3beta1.types.ImportProductSetsGcsSource): - The Google Cloud Storage location for a csv - file which preserves a list of - ImportProductSetRequests in each line. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - oneof='source', - message='ImportProductSetsGcsSource', - ) - - -class ImportProductSetsRequest(proto.Message): - r"""Request message for the ``ImportProductSets`` method. - - Attributes: - parent (str): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - input_config (google.cloud.vision_v1p3beta1.types.ImportProductSetsInputConfig): - Required. The input content for the list of - requests. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - input_config = proto.Field( - proto.MESSAGE, - number=2, - message='ImportProductSetsInputConfig', - ) - - -class ImportProductSetsResponse(proto.Message): - r"""Response message for the ``ImportProductSets`` method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - Attributes: - reference_images (Sequence[google.cloud.vision_v1p3beta1.types.ReferenceImage]): - The list of reference_images that are imported successfully. - statuses (Sequence[google.rpc.status_pb2.Status]): - The rpc status for each ImportProductSet request, including - both successes and errors. - - The number of statuses here matches the number of lines in - the csv file, and statuses[i] stores the success or failure - status of processing the i-th line of the csv, starting from - line 0. - """ - - reference_images = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ReferenceImage', - ) - statuses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=status_pb2.Status, - ) - - -class BatchOperationMetadata(proto.Message): - r"""Metadata for the batch operations such as the current state. - - This is included in the ``metadata`` field of the ``Operation`` - returned by the ``GetOperation`` call of the - ``google::longrunning::Operations`` service. - - Attributes: - state (google.cloud.vision_v1p3beta1.types.BatchOperationMetadata.State): - The current state of the batch operation. - submit_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was submitted - to the server. - end_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request is finished and - [google.longrunning.Operation.done][google.longrunning.Operation.done] - is set to true. - """ - class State(proto.Enum): - r"""Enumerates the possible states that the batch request can be - in. - """ - STATE_UNSPECIFIED = 0 - PROCESSING = 1 - SUCCESSFUL = 2 - FAILED = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - submit_time = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - end_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py deleted file mode 100644 index 1cc4ec5b..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/text_annotation.py +++ /dev/null @@ -1,393 +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.vision_v1p3beta1.types import geometry - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p3beta1', - manifest={ - 'TextAnnotation', - 'Page', - 'Block', - 'Paragraph', - 'Word', - 'Symbol', - }, -) - - -class TextAnnotation(proto.Message): - r"""TextAnnotation contains a structured representation of OCR extracted - text. The hierarchy of an OCR extracted text structure is like this: - TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each - structural component, starting from Page, may further have their own - properties. Properties describe detected languages, breaks etc.. - Please refer to the - [TextAnnotation.TextProperty][google.cloud.vision.v1p3beta1.TextAnnotation.TextProperty] - message definition below for more detail. - - Attributes: - pages (Sequence[google.cloud.vision_v1p3beta1.types.Page]): - List of pages detected by OCR. - text (str): - UTF-8 text detected on the pages. - """ - - 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, - ) - - class DetectedBreak(proto.Message): - r"""Detected start or end of a structural component. - - Attributes: - type_ (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak.BreakType): - Detected break type. - is_prefix (bool): - True if break prepends the element. - """ - class BreakType(proto.Enum): - r"""Enum to denote the type of break found. New line, space etc.""" - UNKNOWN = 0 - SPACE = 1 - SURE_SPACE = 2 - EOL_SURE_SPACE = 3 - HYPHEN = 4 - LINE_BREAK = 5 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='TextAnnotation.DetectedBreak.BreakType', - ) - is_prefix = proto.Field( - proto.BOOL, - number=2, - ) - - class TextProperty(proto.Message): - r"""Additional information detected on the structural component. - - Attributes: - detected_languages (Sequence[google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedLanguage]): - A list of detected languages together with - confidence. - detected_break (google.cloud.vision_v1p3beta1.types.TextAnnotation.DetectedBreak): - Detected start or end of a text segment. - """ - - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='TextAnnotation.DetectedLanguage', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='TextAnnotation.DetectedBreak', - ) - - pages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Page', - ) - text = proto.Field( - proto.STRING, - number=2, - ) - - -class Page(proto.Message): - r"""Detected page from OCR. - - Attributes: - property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): - Additional information detected on the page. - width (int): - Page width. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - height (int): - Page height. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - blocks (Sequence[google.cloud.vision_v1p3beta1.types.Block]): - List of blocks of text, images etc on this - page. - confidence (float): - Confidence of the OCR results on the page. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - width = proto.Field( - proto.INT32, - number=2, - ) - height = proto.Field( - proto.INT32, - number=3, - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Block', - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Block(proto.Message): - r"""Logical element on the page. - - Attributes: - property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - block. - bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding box for the block. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: - - :: - - 0----1 - | | - 3----2 - - - when it's rotated 180 degrees around the top-left corner - it becomes: - - :: - - 2----3 - | | - 1----0 - - and the vertice order will still be (0, 1, 2, 3). - paragraphs (Sequence[google.cloud.vision_v1p3beta1.types.Paragraph]): - List of paragraphs in this block (if this - blocks is of type text). - block_type (google.cloud.vision_v1p3beta1.types.Block.BlockType): - Detected block type (text, image etc) for - this block. - confidence (float): - Confidence of the OCR results on the block. Range [0, 1]. - """ - class BlockType(proto.Enum): - r"""Type of a block (text, image etc) as identified by OCR.""" - UNKNOWN = 0 - TEXT = 1 - TABLE = 2 - PICTURE = 3 - RULER = 4 - BARCODE = 5 - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Paragraph', - ) - block_type = proto.Field( - proto.ENUM, - number=4, - enum=BlockType, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Paragraph(proto.Message): - r"""Structural unit of text representing a number of words in - certain order. - - Attributes: - property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - paragraph. - bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding box for the paragraph. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - words (Sequence[google.cloud.vision_v1p3beta1.types.Word]): - List of words in this paragraph. - confidence (float): - Confidence of the OCR results for the paragraph. Range [0, - 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - words = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Word', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Word(proto.Message): - r"""A word representation. - - Attributes: - property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): - Additional information detected for the word. - bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding box for the word. The vertices are in the order - of top-left, top-right, bottom-right, bottom-left. When a - rotation of the bounding box is detected the rotation is - represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - symbols (Sequence[google.cloud.vision_v1p3beta1.types.Symbol]): - List of symbols in the word. - The order of the symbols follows the natural - reading order. - confidence (float): - Confidence of the OCR results for the word. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - symbols = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Symbol', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Symbol(proto.Message): - r"""A single symbol representation. - - Attributes: - property (google.cloud.vision_v1p3beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - symbol. - bounding_box (google.cloud.vision_v1p3beta1.types.BoundingPoly): - The bounding box for the symbol. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertice order - will still be (0, 1, 2, 3). - text (str): - The actual UTF-8 representation of the - symbol. - confidence (float): - Confidence of the OCR results for the symbol. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - text = proto.Field( - proto.STRING, - number=3, - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py b/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py deleted file mode 100644 index 903d0ce4..00000000 --- a/owl-bot-staging/v1p3beta1/google/cloud/vision_v1p3beta1/types/web_detection.py +++ /dev/null @@ -1,199 +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.vision.v1p3beta1', - manifest={ - 'WebDetection', - }, -) - - -class WebDetection(proto.Message): - r"""Relevant information for the image from the Internet. - - Attributes: - web_entities (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebEntity]): - Deduced entities from similar images on the - Internet. - full_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): - Fully matching images from the Internet. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): - Partial matching images from the Internet. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - pages_with_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebPage]): - Web pages containing the matching images from - the Internet. - visually_similar_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): - The visually similar image results. - best_guess_labels (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebLabel]): - Best guess text labels for the request image. - """ - - class WebEntity(proto.Message): - r"""Entity deduced from similar images on the Internet. - - Attributes: - entity_id (str): - Opaque entity ID. - score (float): - Overall relevancy score for the entity. - Not normalized and not comparable across - different image queries. - description (str): - Canonical description of the entity, in - English. - """ - - entity_id = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - - class WebImage(proto.Message): - r"""Metadata for online images. - - Attributes: - url (str): - The result image URL. - score (float): - (Deprecated) Overall relevancy score for the - image. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - - class WebPage(proto.Message): - r"""Metadata for web pages. - - Attributes: - url (str): - The result web page URL. - score (float): - (Deprecated) Overall relevancy score for the - web page. - page_title (str): - Title for the web page, may contain HTML - markups. - full_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): - Fully matching images on the page. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p3beta1.types.WebDetection.WebImage]): - Partial matching images on the page. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - page_title = proto.Field( - proto.STRING, - number=3, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='WebDetection.WebImage', - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='WebDetection.WebImage', - ) - - class WebLabel(proto.Message): - r"""Label to provide extra metadata for the web detection. - - Attributes: - label (str): - Label for extra metadata. - language_code (str): - The BCP-47 language code for ``label``, such as "en-US" or - "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - """ - - label = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - - web_entities = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=WebEntity, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=WebImage, - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=WebImage, - ) - pages_with_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=WebPage, - ) - visually_similar_images = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=WebImage, - ) - best_guess_labels = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=WebLabel, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p3beta1/mypy.ini b/owl-bot-staging/v1p3beta1/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1p3beta1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1p3beta1/noxfile.py b/owl-bot-staging/v1p3beta1/noxfile.py deleted file mode 100644 index 4c77be9c..00000000 --- a/owl-bot-staging/v1p3beta1/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/vision_v1p3beta1/', - '--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/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py b/owl-bot-staging/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py deleted file mode 100644 index 962a0f93..00000000 --- a/owl-bot-staging/v1p3beta1/scripts/fixup_vision_v1p3beta1_keywords.py +++ /dev/null @@ -1,195 +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 visionCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'add_product_to_product_set': ('name', 'product', ), - 'async_batch_annotate_files': ('requests', ), - 'batch_annotate_images': ('requests', ), - 'create_product': ('parent', 'product', 'product_id', ), - 'create_product_set': ('parent', 'product_set', 'product_set_id', ), - 'create_reference_image': ('parent', 'reference_image', 'reference_image_id', ), - 'delete_product': ('name', ), - 'delete_product_set': ('name', ), - 'delete_reference_image': ('name', ), - 'get_product': ('name', ), - 'get_product_set': ('name', ), - 'get_reference_image': ('name', ), - 'import_product_sets': ('parent', 'input_config', ), - 'list_products': ('parent', 'page_size', 'page_token', ), - 'list_product_sets': ('parent', 'page_size', 'page_token', ), - 'list_products_in_product_set': ('name', 'page_size', 'page_token', ), - 'list_reference_images': ('parent', 'page_size', 'page_token', ), - 'remove_product_from_product_set': ('name', 'product', ), - 'update_product': ('product', 'update_mask', ), - 'update_product_set': ('product_set', 'update_mask', ), - } - - 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: a.keyword.value not 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=visionCallTransformer(), -): - """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 vision 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/v1p3beta1/setup.py b/owl-bot-staging/v1p3beta1/setup.py deleted file mode 100644 index 9d03e702..00000000 --- a/owl-bot-staging/v1p3beta1/setup.py +++ /dev/null @@ -1,54 +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-vision', - 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, < 3.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', - 'Programming Language :: Python :: 3.9', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1p3beta1/tests/__init__.py b/owl-bot-staging/v1p3beta1/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p3beta1/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/v1p3beta1/tests/unit/__init__.py b/owl-bot-staging/v1p3beta1/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p3beta1/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/v1p3beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p3beta1/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/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__init__.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/__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/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py deleted file mode 100644 index fcabadc9..00000000 --- a/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ /dev/null @@ -1,1385 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1p3beta1.services.image_annotator import ImageAnnotatorAsyncClient -from google.cloud.vision_v1p3beta1.services.image_annotator import ImageAnnotatorClient -from google.cloud.vision_v1p3beta1.services.image_annotator import transports -from google.cloud.vision_v1p3beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1p3beta1.types import geometry -from google.cloud.vision_v1p3beta1.types import image_annotator -from google.cloud.vision_v1p3beta1.types import product_search -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ImageAnnotatorGrpcTransport, "grpc"), - (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -def test_image_annotator_client_get_transport_class(): - transport = ImageAnnotatorClient.get_transport_class() - available_transports = [ - transports.ImageAnnotatorGrpcTransport, - ] - assert transport in available_transports - - transport = ImageAnnotatorClient.get_transport_class("grpc") - assert transport == transports.ImageAnnotatorGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - -def test_image_annotator_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ImageAnnotatorClient( - 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, - always_use_jwt_access=True, - ) - - -def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse( - ) - response = client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - -def test_batch_annotate_images_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 = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - client.batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( - )) - response = await client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async_from_dict(): - await test_batch_annotate_images_async(request_type=dict) - - -def test_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -def test_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - -def test_async_batch_annotate_files_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 = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - client.async_batch_annotate_files() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files), - '__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.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async_from_dict(): - await test_async_batch_annotate_files_async(request_type=dict) - - -def test_async_batch_annotate_files_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -def test_async_batch_annotate_files_flattened_error(): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ImageAnnotatorClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, -]) -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 = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ImageAnnotatorGrpcTransport, - ) - -def test_image_annotator_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_image_annotator_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'batch_annotate_images', - 'async_batch_annotate_files', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_image_annotator_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.vision_v1p3beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ImageAnnotatorGrpcTransport, grpc_helpers), - (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_image_annotator_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_host_no_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_image_annotator_host_with_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_image_annotator_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcTransport( - 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_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_grpc_lro_client(): - client = ImageAnnotatorClient( - 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_image_annotator_grpc_lro_async_client(): - client = ImageAnnotatorAsyncClient( - 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_product_path(): - project = "squid" - location = "clam" - product = "whelk" - expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - actual = ImageAnnotatorClient.product_path(project, location, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "project": "octopus", - "location": "oyster", - "product": "nudibranch", - } - path = ImageAnnotatorClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_product_path(path) - assert expected == actual - -def test_product_set_path(): - project = "cuttlefish" - location = "mussel" - product_set = "winkle" - expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - actual = ImageAnnotatorClient.product_set_path(project, location, product_set) - assert expected == actual - - -def test_parse_product_set_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "product_set": "abalone", - } - path = ImageAnnotatorClient.product_set_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_product_set_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ImageAnnotatorClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ImageAnnotatorClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = ImageAnnotatorClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ImageAnnotatorClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ImageAnnotatorClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ImageAnnotatorClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = ImageAnnotatorClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ImageAnnotatorClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ImageAnnotatorClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - transport_class = ImageAnnotatorClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py deleted file mode 100644 index eff5548f..00000000 --- a/owl-bot-staging/v1p3beta1/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ /dev/null @@ -1,6093 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1p3beta1.services.product_search import ProductSearchAsyncClient -from google.cloud.vision_v1p3beta1.services.product_search import ProductSearchClient -from google.cloud.vision_v1p3beta1.services.product_search import pagers -from google.cloud.vision_v1p3beta1.services.product_search import transports -from google.cloud.vision_v1p3beta1.services.product_search.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1p3beta1.types import geometry -from google.cloud.vision_v1p3beta1.types import product_search_service -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -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 ProductSearchClient._get_default_mtls_endpoint(None) is None - assert ProductSearchClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ProductSearchClient, - ProductSearchAsyncClient, -]) -def test_product_search_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductSearchGrpcTransport, "grpc"), - (transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ProductSearchClient, - ProductSearchAsyncClient, -]) -def test_product_search_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 == 'vision.googleapis.com:443' - - -def test_product_search_client_get_transport_class(): - transport = ProductSearchClient.get_transport_class() - available_transports = [ - transports.ProductSearchGrpcTransport, - ] - assert transport in available_transports - - transport = ProductSearchClient.get_transport_class("grpc") - assert transport == transports.ProductSearchGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) -@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) -def test_product_search_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(ProductSearchClient, '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(ProductSearchClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "true"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "false"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) -@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_product_search_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_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, - always_use_jwt_access=True, - ) - - -def test_product_search_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ProductSearchClient( - 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, - always_use_jwt_access=True, - ) - - -def test_create_product_set(transport: str = 'grpc', request_type=product_search_service.CreateProductSetRequest): - client = ProductSearchClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.create_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_create_product_set_from_dict(): - test_create_product_set(request_type=dict) - - -def test_create_product_set_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 = ProductSearchClient( - 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_product_set), - '__call__') as call: - client.create_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - -@pytest.mark.asyncio -async def test_create_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductSetRequest): - client = ProductSearchAsyncClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.create_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_create_product_set_async_from_dict(): - await test_create_product_set_async(request_type=dict) - - -def test_create_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateProductSetRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.create_product_set(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_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateProductSetRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.create_product_set(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_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_product_set( - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].product_set_id == 'product_set_id_value' - - -def test_create_product_set_flattened_error(): - client = ProductSearchClient( - 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_product_set( - product_search_service.CreateProductSetRequest(), - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_product_set( - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].product_set_id == 'product_set_id_value' - - -@pytest.mark.asyncio -async def test_create_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_set( - product_search_service.CreateProductSetRequest(), - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_value', - ) - - -def test_list_product_sets(transport: str = 'grpc', request_type=product_search_service.ListProductSetsRequest): - client = ProductSearchClient( - 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_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductSetsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_product_sets_from_dict(): - test_list_product_sets(request_type=dict) - - -def test_list_product_sets_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 = ProductSearchClient( - 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_product_sets), - '__call__') as call: - client.list_product_sets() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - -@pytest.mark.asyncio -async def test_list_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductSetsRequest): - client = ProductSearchAsyncClient( - 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_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductSetsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_product_sets_async_from_dict(): - await test_list_product_sets_async(request_type=dict) - - -def test_list_product_sets_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - call.return_value = product_search_service.ListProductSetsResponse() - client.list_product_sets(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_product_sets_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) - await client.list_product_sets(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_product_sets_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_product_sets( - 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_product_sets_flattened_error(): - client = ProductSearchClient( - 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_product_sets( - product_search_service.ListProductSetsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_product_sets_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_product_sets( - 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_product_sets_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_sets( - product_search_service.ListProductSetsRequest(), - parent='parent_value', - ) - - -def test_list_product_sets_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_product_sets(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.ProductSet) - for i in results) - -def test_list_product_sets_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - pages = list(client.list_product_sets(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_product_sets_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_product_sets(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, product_search_service.ProductSet) - for i in responses) - -@pytest.mark.asyncio -async def test_list_product_sets_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_product_sets(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_product_set(transport: str = 'grpc', request_type=product_search_service.GetProductSetRequest): - client = ProductSearchClient( - 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.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.get_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_get_product_set_from_dict(): - test_get_product_set(request_type=dict) - - -def test_get_product_set_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 = ProductSearchClient( - 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.get_product_set), - '__call__') as call: - client.get_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - -@pytest.mark.asyncio -async def test_get_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductSetRequest): - client = ProductSearchAsyncClient( - 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.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.get_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_get_product_set_async_from_dict(): - await test_get_product_set_async(request_type=dict) - - -def test_get_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.get_product_set(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_get_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.get_product_set(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_get_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product_set( - 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_get_product_set_flattened_error(): - client = ProductSearchClient( - 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.get_product_set( - product_search_service.GetProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product_set( - 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_get_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_product_set( - product_search_service.GetProductSetRequest(), - name='name_value', - ) - - -def test_update_product_set(transport: str = 'grpc', request_type=product_search_service.UpdateProductSetRequest): - client = ProductSearchClient( - 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.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.update_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_update_product_set_from_dict(): - test_update_product_set(request_type=dict) - - -def test_update_product_set_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 = ProductSearchClient( - 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.update_product_set), - '__call__') as call: - client.update_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - -@pytest.mark.asyncio -async def test_update_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductSetRequest): - client = ProductSearchAsyncClient( - 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.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.update_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_update_product_set_async_from_dict(): - await test_update_product_set_async(request_type=dict) - - -def test_update_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.UpdateProductSetRequest() - - request.product_set.name = 'product_set.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.update_product_set(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', - 'product_set.name=product_set.name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.UpdateProductSetRequest() - - request.product_set.name = 'product_set.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.update_product_set(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', - 'product_set.name=product_set.name/value', - ) in kw['metadata'] - - -def test_update_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product_set( - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -def test_update_product_set_flattened_error(): - client = ProductSearchClient( - 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.update_product_set( - product_search_service.UpdateProductSetRequest(), - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.asyncio -async def test_update_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product_set( - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -@pytest.mark.asyncio -async def test_update_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.update_product_set( - product_search_service.UpdateProductSetRequest(), - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product_set(transport: str = 'grpc', request_type=product_search_service.DeleteProductSetRequest): - client = ProductSearchClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_set_from_dict(): - test_delete_product_set(request_type=dict) - - -def test_delete_product_set_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 = ProductSearchClient( - 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_product_set), - '__call__') as call: - client.delete_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - -@pytest.mark.asyncio -async def test_delete_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductSetRequest): - client = ProductSearchAsyncClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_set_async_from_dict(): - await test_delete_product_set_async(request_type=dict) - - -def test_delete_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - call.return_value = None - client.delete_product_set(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_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product_set(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_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product_set( - 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_product_set_flattened_error(): - client = ProductSearchClient( - 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_product_set( - product_search_service.DeleteProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product_set( - 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_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_set( - product_search_service.DeleteProductSetRequest(), - name='name_value', - ) - - -def test_create_product(transport: str = 'grpc', request_type=product_search_service.CreateProductRequest): - client = ProductSearchClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.create_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_create_product_from_dict(): - test_create_product(request_type=dict) - - -def test_create_product_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 = ProductSearchClient( - 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_product), - '__call__') as call: - client.create_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - -@pytest.mark.asyncio -async def test_create_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductRequest): - client = ProductSearchAsyncClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.create_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_create_product_async_from_dict(): - await test_create_product_async(request_type=dict) - - -def test_create_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateProductRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.create_product(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_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateProductRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.create_product(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_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_product( - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_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].product == product_search_service.Product(name='name_value') - assert args[0].product_id == 'product_id_value' - - -def test_create_product_flattened_error(): - client = ProductSearchClient( - 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_product( - product_search_service.CreateProductRequest(), - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_product( - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_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].product == product_search_service.Product(name='name_value') - assert args[0].product_id == 'product_id_value' - - -@pytest.mark.asyncio -async def test_create_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product( - product_search_service.CreateProductRequest(), - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_value', - ) - - -def test_list_products(transport: str = 'grpc', request_type=product_search_service.ListProductsRequest): - client = ProductSearchClient( - 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_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_from_dict(): - test_list_products(request_type=dict) - - -def test_list_products_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 = ProductSearchClient( - 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_products), - '__call__') as call: - client.list_products() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - -@pytest.mark.asyncio -async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsRequest): - client = ProductSearchAsyncClient( - 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_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_async_from_dict(): - await test_list_products_async(request_type=dict) - - -def test_list_products_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = product_search_service.ListProductsResponse() - client.list_products(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_products_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) - await client.list_products(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_products_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products( - 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_products_flattened_error(): - client = ProductSearchClient( - 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_products( - product_search_service.ListProductsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_products_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products( - 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_products_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_products( - product_search_service.ListProductsRequest(), - parent='parent_value', - ) - - -def test_list_products_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_products(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.Product) - for i in results) - -def test_list_products_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products(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_products_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products(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, product_search_service.Product) - for i in responses) - -@pytest.mark.asyncio -async def test_list_products_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_products(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_product(transport: str = 'grpc', request_type=product_search_service.GetProductRequest): - client = ProductSearchClient( - 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.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_get_product_from_dict(): - test_get_product(request_type=dict) - - -def test_get_product_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 = ProductSearchClient( - 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.get_product), - '__call__') as call: - client.get_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - -@pytest.mark.asyncio -async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductRequest): - client = ProductSearchAsyncClient( - 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.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_get_product_async_from_dict(): - await test_get_product_async(request_type=dict) - - -def test_get_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.get_product(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_get_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.get_product(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_get_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product( - 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_get_product_flattened_error(): - client = ProductSearchClient( - 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.get_product( - product_search_service.GetProductRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product( - 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_get_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_product( - product_search_service.GetProductRequest(), - name='name_value', - ) - - -def test_update_product(transport: str = 'grpc', request_type=product_search_service.UpdateProductRequest): - client = ProductSearchClient( - 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.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.update_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_update_product_from_dict(): - test_update_product(request_type=dict) - - -def test_update_product_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 = ProductSearchClient( - 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.update_product), - '__call__') as call: - client.update_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - -@pytest.mark.asyncio -async def test_update_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductRequest): - client = ProductSearchAsyncClient( - 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.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.update_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_update_product_async_from_dict(): - await test_update_product_async(request_type=dict) - - -def test_update_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.UpdateProductRequest() - - request.product.name = 'product.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.update_product(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', - 'product.name=product.name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.UpdateProductRequest() - - request.product.name = 'product.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.update_product(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', - 'product.name=product.name/value', - ) in kw['metadata'] - - -def test_update_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product( - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -def test_update_product_flattened_error(): - client = ProductSearchClient( - 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.update_product( - product_search_service.UpdateProductRequest(), - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.asyncio -async def test_update_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product( - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -@pytest.mark.asyncio -async def test_update_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.update_product( - product_search_service.UpdateProductRequest(), - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product(transport: str = 'grpc', request_type=product_search_service.DeleteProductRequest): - client = ProductSearchClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_from_dict(): - test_delete_product(request_type=dict) - - -def test_delete_product_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 = ProductSearchClient( - 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_product), - '__call__') as call: - client.delete_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - -@pytest.mark.asyncio -async def test_delete_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductRequest): - client = ProductSearchAsyncClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_async_from_dict(): - await test_delete_product_async(request_type=dict) - - -def test_delete_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - call.return_value = None - client.delete_product(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_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product(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_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product( - 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_product_flattened_error(): - client = ProductSearchClient( - 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_product( - product_search_service.DeleteProductRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product( - 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_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product( - product_search_service.DeleteProductRequest(), - name='name_value', - ) - - -def test_create_reference_image(transport: str = 'grpc', request_type=product_search_service.CreateReferenceImageRequest): - client = ProductSearchClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - ) - response = client.create_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -def test_create_reference_image_from_dict(): - test_create_reference_image(request_type=dict) - - -def test_create_reference_image_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 = ProductSearchClient( - 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_reference_image), - '__call__') as call: - client.create_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_create_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateReferenceImageRequest): - client = ProductSearchAsyncClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - )) - response = await client.create_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -@pytest.mark.asyncio -async def test_create_reference_image_async_from_dict(): - await test_create_reference_image_async(request_type=dict) - - -def test_create_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateReferenceImageRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - call.return_value = product_search_service.ReferenceImage() - client.create_reference_image(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_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateReferenceImageRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - await client.create_reference_image(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_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_reference_image( - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') - assert args[0].reference_image_id == 'reference_image_id_value' - - -def test_create_reference_image_flattened_error(): - client = ProductSearchClient( - 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_reference_image( - product_search_service.CreateReferenceImageRequest(), - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_reference_image( - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') - assert args[0].reference_image_id == 'reference_image_id_value' - - -@pytest.mark.asyncio -async def test_create_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_image( - product_search_service.CreateReferenceImageRequest(), - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_value', - ) - - -def test_delete_reference_image(transport: str = 'grpc', request_type=product_search_service.DeleteReferenceImageRequest): - client = ProductSearchClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_reference_image_from_dict(): - test_delete_reference_image(request_type=dict) - - -def test_delete_reference_image_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 = ProductSearchClient( - 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_reference_image), - '__call__') as call: - client.delete_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_delete_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteReferenceImageRequest): - client = ProductSearchAsyncClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_reference_image_async_from_dict(): - await test_delete_reference_image_async(request_type=dict) - - -def test_delete_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - call.return_value = None - client.delete_reference_image(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_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_reference_image(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_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_reference_image( - 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_reference_image_flattened_error(): - client = ProductSearchClient( - 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_reference_image( - product_search_service.DeleteReferenceImageRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_reference_image( - 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_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_image( - product_search_service.DeleteReferenceImageRequest(), - name='name_value', - ) - - -def test_list_reference_images(transport: str = 'grpc', request_type=product_search_service.ListReferenceImagesRequest): - client = ProductSearchClient( - 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_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse( - page_size=951, - next_page_token='next_page_token_value', - ) - response = client.list_reference_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReferenceImagesPager) - assert response.page_size == 951 - assert response.next_page_token == 'next_page_token_value' - - -def test_list_reference_images_from_dict(): - test_list_reference_images(request_type=dict) - - -def test_list_reference_images_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 = ProductSearchClient( - 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_reference_images), - '__call__') as call: - client.list_reference_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - -@pytest.mark.asyncio -async def test_list_reference_images_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListReferenceImagesRequest): - client = ProductSearchAsyncClient( - 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_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse( - page_size=951, - next_page_token='next_page_token_value', - )) - response = await client.list_reference_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReferenceImagesAsyncPager) - assert response.page_size == 951 - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_reference_images_async_from_dict(): - await test_list_reference_images_async(request_type=dict) - - -def test_list_reference_images_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListReferenceImagesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - call.return_value = product_search_service.ListReferenceImagesResponse() - client.list_reference_images(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_reference_images_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListReferenceImagesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) - await client.list_reference_images(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_reference_images_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_reference_images( - 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_reference_images_flattened_error(): - client = ProductSearchClient( - 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_reference_images( - product_search_service.ListReferenceImagesRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_reference_images_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_reference_images( - 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_reference_images_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_images( - product_search_service.ListReferenceImagesRequest(), - parent='parent_value', - ) - - -def test_list_reference_images_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_reference_images(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.ReferenceImage) - for i in results) - -def test_list_reference_images_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - pages = list(client.list_reference_images(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_reference_images_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_reference_images(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, product_search_service.ReferenceImage) - for i in responses) - -@pytest.mark.asyncio -async def test_list_reference_images_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_reference_images(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_reference_image(transport: str = 'grpc', request_type=product_search_service.GetReferenceImageRequest): - client = ProductSearchClient( - 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.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - ) - response = client.get_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -def test_get_reference_image_from_dict(): - test_get_reference_image(request_type=dict) - - -def test_get_reference_image_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 = ProductSearchClient( - 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.get_reference_image), - '__call__') as call: - client.get_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_get_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetReferenceImageRequest): - client = ProductSearchAsyncClient( - 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.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - )) - response = await client.get_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -@pytest.mark.asyncio -async def test_get_reference_image_async_from_dict(): - await test_get_reference_image_async(request_type=dict) - - -def test_get_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - call.return_value = product_search_service.ReferenceImage() - client.get_reference_image(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_get_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - await client.get_reference_image(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_get_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_reference_image( - 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_get_reference_image_flattened_error(): - client = ProductSearchClient( - 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.get_reference_image( - product_search_service.GetReferenceImageRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_reference_image( - 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_get_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_reference_image( - product_search_service.GetReferenceImageRequest(), - name='name_value', - ) - - -def test_add_product_to_product_set(transport: str = 'grpc', request_type=product_search_service.AddProductToProductSetRequest): - client = ProductSearchClient( - 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.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.add_product_to_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_add_product_to_product_set_from_dict(): - test_add_product_to_product_set(request_type=dict) - - -def test_add_product_to_product_set_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 = ProductSearchClient( - 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.add_product_to_product_set), - '__call__') as call: - client.add_product_to_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.AddProductToProductSetRequest): - client = ProductSearchAsyncClient( - 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.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.add_product_to_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_async_from_dict(): - await test_add_product_to_product_set_async(request_type=dict) - - -def test_add_product_to_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.AddProductToProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - call.return_value = None - client.add_product_to_product_set(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_add_product_to_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.AddProductToProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.add_product_to_product_set(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_add_product_to_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.add_product_to_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -def test_add_product_to_product_set_flattened_error(): - client = ProductSearchClient( - 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.add_product_to_product_set( - product_search_service.AddProductToProductSetRequest(), - name='name_value', - product='product_value', - ) - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.add_product_to_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.add_product_to_product_set( - product_search_service.AddProductToProductSetRequest(), - name='name_value', - product='product_value', - ) - - -def test_remove_product_from_product_set(transport: str = 'grpc', request_type=product_search_service.RemoveProductFromProductSetRequest): - client = ProductSearchClient( - 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.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.remove_product_from_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_remove_product_from_product_set_from_dict(): - test_remove_product_from_product_set(request_type=dict) - - -def test_remove_product_from_product_set_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 = ProductSearchClient( - 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.remove_product_from_product_set), - '__call__') as call: - client.remove_product_from_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.RemoveProductFromProductSetRequest): - client = ProductSearchAsyncClient( - 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.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.remove_product_from_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_async_from_dict(): - await test_remove_product_from_product_set_async(request_type=dict) - - -def test_remove_product_from_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.RemoveProductFromProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - call.return_value = None - client.remove_product_from_product_set(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_remove_product_from_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.RemoveProductFromProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.remove_product_from_product_set(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_remove_product_from_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.remove_product_from_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -def test_remove_product_from_product_set_flattened_error(): - client = ProductSearchClient( - 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.remove_product_from_product_set( - product_search_service.RemoveProductFromProductSetRequest(), - name='name_value', - product='product_value', - ) - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.remove_product_from_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.remove_product_from_product_set( - product_search_service.RemoveProductFromProductSetRequest(), - name='name_value', - product='product_value', - ) - - -def test_list_products_in_product_set(transport: str = 'grpc', request_type=product_search_service.ListProductsInProductSetRequest): - client = ProductSearchClient( - 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_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products_in_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsInProductSetPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_in_product_set_from_dict(): - test_list_products_in_product_set(request_type=dict) - - -def test_list_products_in_product_set_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 = ProductSearchClient( - 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_products_in_product_set), - '__call__') as call: - client.list_products_in_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsInProductSetRequest): - client = ProductSearchAsyncClient( - 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_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products_in_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsInProductSetAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async_from_dict(): - await test_list_products_in_product_set_async(request_type=dict) - - -def test_list_products_in_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductsInProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - call.return_value = product_search_service.ListProductsInProductSetResponse() - client.list_products_in_product_set(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_list_products_in_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductsInProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) - await client.list_products_in_product_set(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_list_products_in_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products_in_product_set( - 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_list_products_in_product_set_flattened_error(): - client = ProductSearchClient( - 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_products_in_product_set( - product_search_service.ListProductsInProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products_in_product_set( - 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_list_products_in_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_products_in_product_set( - product_search_service.ListProductsInProductSetRequest(), - name='name_value', - ) - - -def test_list_products_in_product_set_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('name', ''), - )), - ) - pager = client.list_products_in_product_set(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.Product) - for i in results) - -def test_list_products_in_product_set_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products_in_product_set(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_products_in_product_set_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products_in_product_set(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, product_search_service.Product) - for i in responses) - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_products_in_product_set(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_import_product_sets(transport: str = 'grpc', request_type=product_search_service.ImportProductSetsRequest): - client = ProductSearchClient( - 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.import_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.import_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_import_product_sets_from_dict(): - test_import_product_sets(request_type=dict) - - -def test_import_product_sets_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 = ProductSearchClient( - 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.import_product_sets), - '__call__') as call: - client.import_product_sets() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - -@pytest.mark.asyncio -async def test_import_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ImportProductSetsRequest): - client = ProductSearchAsyncClient( - 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.import_product_sets), - '__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.import_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_import_product_sets_async_from_dict(): - await test_import_product_sets_async(request_type=dict) - - -def test_import_product_sets_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ImportProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.import_product_sets(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_import_product_sets_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ImportProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.import_product_sets(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_import_product_sets_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__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.import_product_sets( - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) - - -def test_import_product_sets_flattened_error(): - client = ProductSearchClient( - 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.import_product_sets( - product_search_service.ImportProductSetsRequest(), - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), - ) - - -@pytest.mark.asyncio -async def test_import_product_sets_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__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.import_product_sets( - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) - - -@pytest.mark.asyncio -async def test_import_product_sets_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.import_product_sets( - product_search_service.ImportProductSetsRequest(), - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ProductSearchClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ProductSearchGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, -]) -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 = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ProductSearchGrpcTransport, - ) - -def test_product_search_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ProductSearchTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_product_search_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ProductSearchTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'create_product_set', - 'list_product_sets', - 'get_product_set', - 'update_product_set', - 'delete_product_set', - 'create_product', - 'list_products', - 'get_product', - 'update_product', - 'delete_product', - 'create_reference_image', - 'delete_reference_image', - 'list_reference_images', - 'get_reference_image', - 'add_product_to_product_set', - 'remove_product_from_product_set', - 'list_products_in_product_set', - 'import_product_sets', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_product_search_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.vision_v1p3beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_product_search_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_product_search_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ProductSearchGrpcTransport, grpc_helpers), - (transports.ProductSearchGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_product_search_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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_product_search_host_no_port(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_product_search_host_with_port(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_product_search_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductSearchGrpcTransport( - 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_product_search_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductSearchGrpcAsyncIOTransport( - 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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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_product_search_grpc_lro_client(): - client = ProductSearchClient( - 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_product_search_grpc_lro_async_client(): - client = ProductSearchAsyncClient( - 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_product_path(): - project = "squid" - location = "clam" - product = "whelk" - expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - actual = ProductSearchClient.product_path(project, location, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "project": "octopus", - "location": "oyster", - "product": "nudibranch", - } - path = ProductSearchClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_product_path(path) - assert expected == actual - -def test_product_set_path(): - project = "cuttlefish" - location = "mussel" - product_set = "winkle" - expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - actual = ProductSearchClient.product_set_path(project, location, product_set) - assert expected == actual - - -def test_parse_product_set_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "product_set": "abalone", - } - path = ProductSearchClient.product_set_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_product_set_path(path) - assert expected == actual - -def test_reference_image_path(): - project = "squid" - location = "clam" - product = "whelk" - reference_image = "octopus" - expected = "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) - actual = ProductSearchClient.reference_image_path(project, location, product, reference_image) - assert expected == actual - - -def test_parse_reference_image_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "product": "cuttlefish", - "reference_image": "mussel", - } - path = ProductSearchClient.reference_image_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_reference_image_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ProductSearchClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nautilus", - } - path = ProductSearchClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "scallop" - expected = "folders/{folder}".format(folder=folder, ) - actual = ProductSearchClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "abalone", - } - path = ProductSearchClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "squid" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ProductSearchClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "clam", - } - path = ProductSearchClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "whelk" - expected = "projects/{project}".format(project=project, ) - actual = ProductSearchClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "octopus", - } - path = ProductSearchClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "oyster" - location = "nudibranch" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = ProductSearchClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - } - path = ProductSearchClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.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.ProductSearchTransport, '_prep_wrapped_messages') as prep: - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ProductSearchTransport, '_prep_wrapped_messages') as prep: - transport_class = ProductSearchClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1p4beta1/.coveragerc b/owl-bot-staging/v1p4beta1/.coveragerc deleted file mode 100644 index 75747063..00000000 --- a/owl-bot-staging/v1p4beta1/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/vision/__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/v1p4beta1/MANIFEST.in b/owl-bot-staging/v1p4beta1/MANIFEST.in deleted file mode 100644 index 47dfa0c1..00000000 --- a/owl-bot-staging/v1p4beta1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/vision *.py -recursive-include google/cloud/vision_v1p4beta1 *.py diff --git a/owl-bot-staging/v1p4beta1/README.rst b/owl-bot-staging/v1p4beta1/README.rst deleted file mode 100644 index 39f9ca72..00000000 --- a/owl-bot-staging/v1p4beta1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Vision 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 Vision 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/v1p4beta1/docs/conf.py b/owl-bot-staging/v1p4beta1/docs/conf.py deleted file mode 100644 index 6e730bf5..00000000 --- a/owl-bot-staging/v1p4beta1/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-vision 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-vision" -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-vision-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-vision.tex", - u"google-cloud-vision 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-vision", - u"Google Cloud Vision 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-vision", - u"google-cloud-vision Documentation", - author, - "google-cloud-vision", - "GAPIC library for Google Cloud Vision 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/v1p4beta1/docs/index.rst b/owl-bot-staging/v1p4beta1/docs/index.rst deleted file mode 100644 index ea7e0477..00000000 --- a/owl-bot-staging/v1p4beta1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - vision_v1p4beta1/services - vision_v1p4beta1/types diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst deleted file mode 100644 index 28717262..00000000 --- a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/image_annotator.rst +++ /dev/null @@ -1,6 +0,0 @@ -ImageAnnotator --------------------------------- - -.. automodule:: google.cloud.vision_v1p4beta1.services.image_annotator - :members: - :inherited-members: diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst deleted file mode 100644 index 895f0cba..00000000 --- a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/product_search.rst +++ /dev/null @@ -1,10 +0,0 @@ -ProductSearch -------------------------------- - -.. automodule:: google.cloud.vision_v1p4beta1.services.product_search - :members: - :inherited-members: - -.. automodule:: google.cloud.vision_v1p4beta1.services.product_search.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst deleted file mode 100644 index 2ebd0bbc..00000000 --- a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/services.rst +++ /dev/null @@ -1,7 +0,0 @@ -Services for Google Cloud Vision v1p4beta1 API -============================================== -.. toctree:: - :maxdepth: 2 - - image_annotator - product_search diff --git a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst b/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst deleted file mode 100644 index a90d1fa2..00000000 --- a/owl-bot-staging/v1p4beta1/docs/vision_v1p4beta1/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Vision v1p4beta1 API -=========================================== - -.. automodule:: google.cloud.vision_v1p4beta1.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py deleted file mode 100644 index 038c8422..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision/__init__.py +++ /dev/null @@ -1,201 +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.vision_v1p4beta1.services.image_annotator.client import ImageAnnotatorClient -from google.cloud.vision_v1p4beta1.services.image_annotator.async_client import ImageAnnotatorAsyncClient -from google.cloud.vision_v1p4beta1.services.product_search.client import ProductSearchClient -from google.cloud.vision_v1p4beta1.services.product_search.async_client import ProductSearchAsyncClient - -from google.cloud.vision_v1p4beta1.types.face import Celebrity -from google.cloud.vision_v1p4beta1.types.face import FaceRecognitionParams -from google.cloud.vision_v1p4beta1.types.face import FaceRecognitionResult -from google.cloud.vision_v1p4beta1.types.geometry import BoundingPoly -from google.cloud.vision_v1p4beta1.types.geometry import NormalizedVertex -from google.cloud.vision_v1p4beta1.types.geometry import Position -from google.cloud.vision_v1p4beta1.types.geometry import Vertex -from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateFileRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateFileResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateImageRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import AnnotateImageResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncAnnotateFileRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncAnnotateFileResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateFilesRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateFilesResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateImagesRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import AsyncBatchAnnotateImagesResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateFilesRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateFilesResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateImagesRequest -from google.cloud.vision_v1p4beta1.types.image_annotator import BatchAnnotateImagesResponse -from google.cloud.vision_v1p4beta1.types.image_annotator import ColorInfo -from google.cloud.vision_v1p4beta1.types.image_annotator import CropHint -from google.cloud.vision_v1p4beta1.types.image_annotator import CropHintsAnnotation -from google.cloud.vision_v1p4beta1.types.image_annotator import CropHintsParams -from google.cloud.vision_v1p4beta1.types.image_annotator import DominantColorsAnnotation -from google.cloud.vision_v1p4beta1.types.image_annotator import EntityAnnotation -from google.cloud.vision_v1p4beta1.types.image_annotator import FaceAnnotation -from google.cloud.vision_v1p4beta1.types.image_annotator import Feature -from google.cloud.vision_v1p4beta1.types.image_annotator import GcsDestination -from google.cloud.vision_v1p4beta1.types.image_annotator import GcsSource -from google.cloud.vision_v1p4beta1.types.image_annotator import Image -from google.cloud.vision_v1p4beta1.types.image_annotator import ImageAnnotationContext -from google.cloud.vision_v1p4beta1.types.image_annotator import ImageContext -from google.cloud.vision_v1p4beta1.types.image_annotator import ImageProperties -from google.cloud.vision_v1p4beta1.types.image_annotator import ImageSource -from google.cloud.vision_v1p4beta1.types.image_annotator import InputConfig -from google.cloud.vision_v1p4beta1.types.image_annotator import LatLongRect -from google.cloud.vision_v1p4beta1.types.image_annotator import LocalizedObjectAnnotation -from google.cloud.vision_v1p4beta1.types.image_annotator import LocationInfo -from google.cloud.vision_v1p4beta1.types.image_annotator import OperationMetadata -from google.cloud.vision_v1p4beta1.types.image_annotator import OutputConfig -from google.cloud.vision_v1p4beta1.types.image_annotator import Property -from google.cloud.vision_v1p4beta1.types.image_annotator import SafeSearchAnnotation -from google.cloud.vision_v1p4beta1.types.image_annotator import TextDetectionParams -from google.cloud.vision_v1p4beta1.types.image_annotator import WebDetectionParams -from google.cloud.vision_v1p4beta1.types.image_annotator import Likelihood -from google.cloud.vision_v1p4beta1.types.product_search import ProductSearchParams -from google.cloud.vision_v1p4beta1.types.product_search import ProductSearchResults -from google.cloud.vision_v1p4beta1.types.product_search_service import AddProductToProductSetRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import BatchOperationMetadata -from google.cloud.vision_v1p4beta1.types.product_search_service import CreateProductRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import CreateProductSetRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import CreateReferenceImageRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import DeleteProductRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import DeleteProductSetRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import DeleteReferenceImageRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import GetProductRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import GetProductSetRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import GetReferenceImageRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsGcsSource -from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsInputConfig -from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ImportProductSetsResponse -from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductSetsRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductSetsResponse -from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsInProductSetRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsInProductSetResponse -from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ListProductsResponse -from google.cloud.vision_v1p4beta1.types.product_search_service import ListReferenceImagesRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ListReferenceImagesResponse -from google.cloud.vision_v1p4beta1.types.product_search_service import Product -from google.cloud.vision_v1p4beta1.types.product_search_service import ProductSet -from google.cloud.vision_v1p4beta1.types.product_search_service import ProductSetPurgeConfig -from google.cloud.vision_v1p4beta1.types.product_search_service import PurgeProductsRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import ReferenceImage -from google.cloud.vision_v1p4beta1.types.product_search_service import RemoveProductFromProductSetRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import UpdateProductRequest -from google.cloud.vision_v1p4beta1.types.product_search_service import UpdateProductSetRequest -from google.cloud.vision_v1p4beta1.types.text_annotation import Block -from google.cloud.vision_v1p4beta1.types.text_annotation import Page -from google.cloud.vision_v1p4beta1.types.text_annotation import Paragraph -from google.cloud.vision_v1p4beta1.types.text_annotation import Symbol -from google.cloud.vision_v1p4beta1.types.text_annotation import TextAnnotation -from google.cloud.vision_v1p4beta1.types.text_annotation import Word -from google.cloud.vision_v1p4beta1.types.web_detection import WebDetection - -__all__ = ('ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', - 'ProductSearchClient', - 'ProductSearchAsyncClient', - 'Celebrity', - 'FaceRecognitionParams', - 'FaceRecognitionResult', - 'BoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileRequest', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'AsyncBatchAnnotateImagesRequest', - 'AsyncBatchAnnotateImagesResponse', - 'BatchAnnotateFilesRequest', - 'BatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocalizedObjectAnnotation', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'ProductSearchParams', - 'ProductSearchResults', - 'AddProductToProductSetRequest', - 'BatchOperationMetadata', - 'CreateProductRequest', - 'CreateProductSetRequest', - 'CreateReferenceImageRequest', - 'DeleteProductRequest', - 'DeleteProductSetRequest', - 'DeleteReferenceImageRequest', - 'GetProductRequest', - 'GetProductSetRequest', - 'GetReferenceImageRequest', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ListProductsRequest', - 'ListProductsResponse', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'Product', - 'ProductSet', - 'ProductSetPurgeConfig', - 'PurgeProductsRequest', - 'ReferenceImage', - 'RemoveProductFromProductSetRequest', - 'UpdateProductRequest', - 'UpdateProductSetRequest', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed b/owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py deleted file mode 100644 index 2464becd..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/__init__.py +++ /dev/null @@ -1,202 +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.image_annotator import ImageAnnotatorClient -from .services.image_annotator import ImageAnnotatorAsyncClient -from .services.product_search import ProductSearchClient -from .services.product_search import ProductSearchAsyncClient - -from .types.face import Celebrity -from .types.face import FaceRecognitionParams -from .types.face import FaceRecognitionResult -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Position -from .types.geometry import Vertex -from .types.image_annotator import AnnotateFileRequest -from .types.image_annotator import AnnotateFileResponse -from .types.image_annotator import AnnotateImageRequest -from .types.image_annotator import AnnotateImageResponse -from .types.image_annotator import AsyncAnnotateFileRequest -from .types.image_annotator import AsyncAnnotateFileResponse -from .types.image_annotator import AsyncBatchAnnotateFilesRequest -from .types.image_annotator import AsyncBatchAnnotateFilesResponse -from .types.image_annotator import AsyncBatchAnnotateImagesRequest -from .types.image_annotator import AsyncBatchAnnotateImagesResponse -from .types.image_annotator import BatchAnnotateFilesRequest -from .types.image_annotator import BatchAnnotateFilesResponse -from .types.image_annotator import BatchAnnotateImagesRequest -from .types.image_annotator import BatchAnnotateImagesResponse -from .types.image_annotator import ColorInfo -from .types.image_annotator import CropHint -from .types.image_annotator import CropHintsAnnotation -from .types.image_annotator import CropHintsParams -from .types.image_annotator import DominantColorsAnnotation -from .types.image_annotator import EntityAnnotation -from .types.image_annotator import FaceAnnotation -from .types.image_annotator import Feature -from .types.image_annotator import GcsDestination -from .types.image_annotator import GcsSource -from .types.image_annotator import Image -from .types.image_annotator import ImageAnnotationContext -from .types.image_annotator import ImageContext -from .types.image_annotator import ImageProperties -from .types.image_annotator import ImageSource -from .types.image_annotator import InputConfig -from .types.image_annotator import LatLongRect -from .types.image_annotator import LocalizedObjectAnnotation -from .types.image_annotator import LocationInfo -from .types.image_annotator import OperationMetadata -from .types.image_annotator import OutputConfig -from .types.image_annotator import Property -from .types.image_annotator import SafeSearchAnnotation -from .types.image_annotator import TextDetectionParams -from .types.image_annotator import WebDetectionParams -from .types.image_annotator import Likelihood -from .types.product_search import ProductSearchParams -from .types.product_search import ProductSearchResults -from .types.product_search_service import AddProductToProductSetRequest -from .types.product_search_service import BatchOperationMetadata -from .types.product_search_service import CreateProductRequest -from .types.product_search_service import CreateProductSetRequest -from .types.product_search_service import CreateReferenceImageRequest -from .types.product_search_service import DeleteProductRequest -from .types.product_search_service import DeleteProductSetRequest -from .types.product_search_service import DeleteReferenceImageRequest -from .types.product_search_service import GetProductRequest -from .types.product_search_service import GetProductSetRequest -from .types.product_search_service import GetReferenceImageRequest -from .types.product_search_service import ImportProductSetsGcsSource -from .types.product_search_service import ImportProductSetsInputConfig -from .types.product_search_service import ImportProductSetsRequest -from .types.product_search_service import ImportProductSetsResponse -from .types.product_search_service import ListProductSetsRequest -from .types.product_search_service import ListProductSetsResponse -from .types.product_search_service import ListProductsInProductSetRequest -from .types.product_search_service import ListProductsInProductSetResponse -from .types.product_search_service import ListProductsRequest -from .types.product_search_service import ListProductsResponse -from .types.product_search_service import ListReferenceImagesRequest -from .types.product_search_service import ListReferenceImagesResponse -from .types.product_search_service import Product -from .types.product_search_service import ProductSet -from .types.product_search_service import ProductSetPurgeConfig -from .types.product_search_service import PurgeProductsRequest -from .types.product_search_service import ReferenceImage -from .types.product_search_service import RemoveProductFromProductSetRequest -from .types.product_search_service import UpdateProductRequest -from .types.product_search_service import UpdateProductSetRequest -from .types.text_annotation import Block -from .types.text_annotation import Page -from .types.text_annotation import Paragraph -from .types.text_annotation import Symbol -from .types.text_annotation import TextAnnotation -from .types.text_annotation import Word -from .types.web_detection import WebDetection - -__all__ = ( - 'ImageAnnotatorAsyncClient', - 'ProductSearchAsyncClient', -'AddProductToProductSetRequest', -'AnnotateFileRequest', -'AnnotateFileResponse', -'AnnotateImageRequest', -'AnnotateImageResponse', -'AsyncAnnotateFileRequest', -'AsyncAnnotateFileResponse', -'AsyncBatchAnnotateFilesRequest', -'AsyncBatchAnnotateFilesResponse', -'AsyncBatchAnnotateImagesRequest', -'AsyncBatchAnnotateImagesResponse', -'BatchAnnotateFilesRequest', -'BatchAnnotateFilesResponse', -'BatchAnnotateImagesRequest', -'BatchAnnotateImagesResponse', -'BatchOperationMetadata', -'Block', -'BoundingPoly', -'Celebrity', -'ColorInfo', -'CreateProductRequest', -'CreateProductSetRequest', -'CreateReferenceImageRequest', -'CropHint', -'CropHintsAnnotation', -'CropHintsParams', -'DeleteProductRequest', -'DeleteProductSetRequest', -'DeleteReferenceImageRequest', -'DominantColorsAnnotation', -'EntityAnnotation', -'FaceAnnotation', -'FaceRecognitionParams', -'FaceRecognitionResult', -'Feature', -'GcsDestination', -'GcsSource', -'GetProductRequest', -'GetProductSetRequest', -'GetReferenceImageRequest', -'Image', -'ImageAnnotationContext', -'ImageAnnotatorClient', -'ImageContext', -'ImageProperties', -'ImageSource', -'ImportProductSetsGcsSource', -'ImportProductSetsInputConfig', -'ImportProductSetsRequest', -'ImportProductSetsResponse', -'InputConfig', -'LatLongRect', -'Likelihood', -'ListProductSetsRequest', -'ListProductSetsResponse', -'ListProductsInProductSetRequest', -'ListProductsInProductSetResponse', -'ListProductsRequest', -'ListProductsResponse', -'ListReferenceImagesRequest', -'ListReferenceImagesResponse', -'LocalizedObjectAnnotation', -'LocationInfo', -'NormalizedVertex', -'OperationMetadata', -'OutputConfig', -'Page', -'Paragraph', -'Position', -'Product', -'ProductSearchClient', -'ProductSearchParams', -'ProductSearchResults', -'ProductSet', -'ProductSetPurgeConfig', -'Property', -'PurgeProductsRequest', -'ReferenceImage', -'RemoveProductFromProductSetRequest', -'SafeSearchAnnotation', -'Symbol', -'TextAnnotation', -'TextDetectionParams', -'UpdateProductRequest', -'UpdateProductSetRequest', -'Vertex', -'WebDetection', -'WebDetectionParams', -'Word', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json deleted file mode 100644 index bc41c344..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/gapic_metadata.json +++ /dev/null @@ -1,267 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.vision_v1p4beta1", - "protoPackage": "google.cloud.vision.v1p4beta1", - "schema": "1.0", - "services": { - "ImageAnnotator": { - "clients": { - "grpc": { - "libraryClient": "ImageAnnotatorClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "AsyncBatchAnnotateImages": { - "methods": [ - "async_batch_annotate_images" - ] - }, - "BatchAnnotateFiles": { - "methods": [ - "batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ImageAnnotatorAsyncClient", - "rpcs": { - "AsyncBatchAnnotateFiles": { - "methods": [ - "async_batch_annotate_files" - ] - }, - "AsyncBatchAnnotateImages": { - "methods": [ - "async_batch_annotate_images" - ] - }, - "BatchAnnotateFiles": { - "methods": [ - "batch_annotate_files" - ] - }, - "BatchAnnotateImages": { - "methods": [ - "batch_annotate_images" - ] - } - } - } - } - }, - "ProductSearch": { - "clients": { - "grpc": { - "libraryClient": "ProductSearchClient", - "rpcs": { - "AddProductToProductSet": { - "methods": [ - "add_product_to_product_set" - ] - }, - "CreateProduct": { - "methods": [ - "create_product" - ] - }, - "CreateProductSet": { - "methods": [ - "create_product_set" - ] - }, - "CreateReferenceImage": { - "methods": [ - "create_reference_image" - ] - }, - "DeleteProduct": { - "methods": [ - "delete_product" - ] - }, - "DeleteProductSet": { - "methods": [ - "delete_product_set" - ] - }, - "DeleteReferenceImage": { - "methods": [ - "delete_reference_image" - ] - }, - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "GetProductSet": { - "methods": [ - "get_product_set" - ] - }, - "GetReferenceImage": { - "methods": [ - "get_reference_image" - ] - }, - "ImportProductSets": { - "methods": [ - "import_product_sets" - ] - }, - "ListProductSets": { - "methods": [ - "list_product_sets" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - }, - "ListProductsInProductSet": { - "methods": [ - "list_products_in_product_set" - ] - }, - "ListReferenceImages": { - "methods": [ - "list_reference_images" - ] - }, - "PurgeProducts": { - "methods": [ - "purge_products" - ] - }, - "RemoveProductFromProductSet": { - "methods": [ - "remove_product_from_product_set" - ] - }, - "UpdateProduct": { - "methods": [ - "update_product" - ] - }, - "UpdateProductSet": { - "methods": [ - "update_product_set" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ProductSearchAsyncClient", - "rpcs": { - "AddProductToProductSet": { - "methods": [ - "add_product_to_product_set" - ] - }, - "CreateProduct": { - "methods": [ - "create_product" - ] - }, - "CreateProductSet": { - "methods": [ - "create_product_set" - ] - }, - "CreateReferenceImage": { - "methods": [ - "create_reference_image" - ] - }, - "DeleteProduct": { - "methods": [ - "delete_product" - ] - }, - "DeleteProductSet": { - "methods": [ - "delete_product_set" - ] - }, - "DeleteReferenceImage": { - "methods": [ - "delete_reference_image" - ] - }, - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "GetProductSet": { - "methods": [ - "get_product_set" - ] - }, - "GetReferenceImage": { - "methods": [ - "get_reference_image" - ] - }, - "ImportProductSets": { - "methods": [ - "import_product_sets" - ] - }, - "ListProductSets": { - "methods": [ - "list_product_sets" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - }, - "ListProductsInProductSet": { - "methods": [ - "list_products_in_product_set" - ] - }, - "ListReferenceImages": { - "methods": [ - "list_reference_images" - ] - }, - "PurgeProducts": { - "methods": [ - "purge_products" - ] - }, - "RemoveProductFromProductSet": { - "methods": [ - "remove_product_from_product_set" - ] - }, - "UpdateProduct": { - "methods": [ - "update_product" - ] - }, - "UpdateProductSet": { - "methods": [ - "update_product_set" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed deleted file mode 100644 index 8cb07491..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-vision package uses inline types. diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/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/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__init__.py deleted file mode 100644 index 3cbfa2fa..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/__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 ImageAnnotatorClient -from .async_client import ImageAnnotatorAsyncClient - -__all__ = ( - 'ImageAnnotatorClient', - 'ImageAnnotatorAsyncClient', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py deleted file mode 100644 index 1b40908d..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/async_client.py +++ /dev/null @@ -1,517 +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.vision_v1p4beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport -from .client import ImageAnnotatorClient - - -class ImageAnnotatorAsyncClient: - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - _client: ImageAnnotatorClient - - DEFAULT_ENDPOINT = ImageAnnotatorClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ImageAnnotatorClient.DEFAULT_MTLS_ENDPOINT - - product_path = staticmethod(ImageAnnotatorClient.product_path) - parse_product_path = staticmethod(ImageAnnotatorClient.parse_product_path) - product_set_path = staticmethod(ImageAnnotatorClient.product_set_path) - parse_product_set_path = staticmethod(ImageAnnotatorClient.parse_product_set_path) - common_billing_account_path = staticmethod(ImageAnnotatorClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ImageAnnotatorClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ImageAnnotatorClient.common_folder_path) - parse_common_folder_path = staticmethod(ImageAnnotatorClient.parse_common_folder_path) - common_organization_path = staticmethod(ImageAnnotatorClient.common_organization_path) - parse_common_organization_path = staticmethod(ImageAnnotatorClient.parse_common_organization_path) - common_project_path = staticmethod(ImageAnnotatorClient.common_project_path) - parse_common_project_path = staticmethod(ImageAnnotatorClient.parse_common_project_path) - common_location_path = staticmethod(ImageAnnotatorClient.common_location_path) - parse_common_location_path = staticmethod(ImageAnnotatorClient.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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_info.__func__(ImageAnnotatorAsyncClient, 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: - ImageAnnotatorAsyncClient: The constructed client. - """ - return ImageAnnotatorClient.from_service_account_file.__func__(ImageAnnotatorAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ImageAnnotatorClient).get_transport_class, type(ImageAnnotatorClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ImageAnnotatorTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ~.ImageAnnotatorTransport]): 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 = ImageAnnotatorClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def batch_annotate_images(self, - request: image_annotator.BatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest`): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1p4beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 = image_annotator.BatchAnnotateImagesRequest(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_annotate_images, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def batch_annotate_files(self, - request: image_annotator.BatchAnnotateFilesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateFilesResponse: - r"""Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest`): - The request object. A list of requests to annotate files - using the BatchAnnotateFiles API. - requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]`): - Required. The list of file annotation - requests. Right now we support only one - AnnotateFileRequest in - BatchAnnotateFilesRequest. - - 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.cloud.vision_v1p4beta1.types.BatchAnnotateFilesResponse: - A list of file annotation responses. - """ - # 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 = image_annotator.BatchAnnotateFilesRequest(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_annotate_files, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def async_batch_annotate_images(self, - request: image_annotator.AsyncBatchAnnotateImagesRequest = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - output_config: image_annotator.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest`): - The request object. Request for async image annotation - for a list of images. - requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]`): - Required. Individual image annotation - requests for this batch. - - This corresponds to the ``requests`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - output_config (:class:`google.cloud.vision_v1p4beta1.types.OutputConfig`): - Required. The desired output location - and metadata (e.g. format). - - This corresponds to the ``output_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.vision_v1p4beta1.types.AsyncBatchAnnotateImagesResponse` - Response to an async batch image annotation request. - - """ - # 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, output_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 = image_annotator.AsyncBatchAnnotateImagesRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if output_config is not None: - request.output_config = output_config - 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.async_batch_annotate_images, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # 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, - image_annotator.AsyncBatchAnnotateImagesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - async def async_batch_annotate_files(self, - request: image_annotator.AsyncBatchAnnotateFilesRequest = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest`): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (:class:`Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]`): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1p4beta1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorAsyncClient", -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py deleted file mode 100644 index 0b78b6a3..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/client.py +++ /dev/null @@ -1,703 +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 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.vision_v1p4beta1.types import image_annotator -from .transports.base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ImageAnnotatorGrpcTransport -from .transports.grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -class ImageAnnotatorClientMeta(type): - """Metaclass for the ImageAnnotator 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[ImageAnnotatorTransport]] - _transport_registry["grpc"] = ImageAnnotatorGrpcTransport - _transport_registry["grpc_asyncio"] = ImageAnnotatorGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ImageAnnotatorTransport]: - """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 ImageAnnotatorClient(metaclass=ImageAnnotatorClientMeta): - """Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - """ - - @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 = "vision.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: - ImageAnnotatorClient: 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: - ImageAnnotatorClient: 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) -> ImageAnnotatorTransport: - """Returns the transport used by the client instance. - - Returns: - ImageAnnotatorTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(project: str,location: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_set_path(project: str,location: str,product_set: str,) -> str: - """Returns a fully-qualified product_set string.""" - return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - - @staticmethod - def parse_product_set_path(path: str) -> Dict[str,str]: - """Parses a product_set path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?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, ImageAnnotatorTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the image annotator 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, ImageAnnotatorTransport]): 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, ImageAnnotatorTransport): - # transport is a ImageAnnotatorTransport 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, - always_use_jwt_access=True, - ) - - def batch_annotate_images(self, - request: Union[image_annotator.BatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateImagesResponse: - r"""Run image detection and annotation for a batch of - images. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateImagesRequest, dict]): - The request object. Multiple image annotation requests - are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - - 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.cloud.vision_v1p4beta1.types.BatchAnnotateImagesResponse: - Response to a batch image annotation - request. - - """ - # 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 image_annotator.BatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateImagesRequest): - request = image_annotator.BatchAnnotateImagesRequest(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_annotate_images] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def batch_annotate_files(self, - request: Union[image_annotator.BatchAnnotateFilesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> image_annotator.BatchAnnotateFilesResponse: - r"""Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.BatchAnnotateFilesRequest, dict]): - The request object. A list of requests to annotate files - using the BatchAnnotateFiles API. - requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]): - Required. The list of file annotation - requests. Right now we support only one - AnnotateFileRequest in - BatchAnnotateFilesRequest. - - 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.cloud.vision_v1p4beta1.types.BatchAnnotateFilesResponse: - A list of file annotation responses. - """ - # 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 image_annotator.BatchAnnotateFilesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.BatchAnnotateFilesRequest): - request = image_annotator.BatchAnnotateFilesRequest(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_annotate_files] - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def async_batch_annotate_images(self, - request: Union[image_annotator.AsyncBatchAnnotateImagesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AnnotateImageRequest] = None, - output_config: image_annotator.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateImagesRequest, dict]): - The request object. Request for async image annotation - for a list of images. - requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - - This corresponds to the ``requests`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): - Required. The desired output location - and metadata (e.g. format). - - This corresponds to the ``output_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.vision_v1p4beta1.types.AsyncBatchAnnotateImagesResponse` - Response to an async batch image annotation request. - - """ - # 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, output_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 image_annotator.AsyncBatchAnnotateImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.AsyncBatchAnnotateImagesRequest): - request = image_annotator.AsyncBatchAnnotateImagesRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if requests is not None: - request.requests = requests - if output_config is not None: - request.output_config = output_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.async_batch_annotate_images] - - # 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, - image_annotator.AsyncBatchAnnotateImagesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - def async_batch_annotate_files(self, - request: Union[image_annotator.AsyncBatchAnnotateFilesRequest, dict] = None, - *, - requests: Sequence[image_annotator.AsyncAnnotateFileRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.AsyncBatchAnnotateFilesRequest, dict]): - The request object. Multiple async file annotation - requests are batched into a single service call. - requests (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]): - Required. Individual async file - annotation requests for this batch. - - 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.vision_v1p4beta1.types.AsyncBatchAnnotateFilesResponse` - Response to an async batch file annotation request. - - """ - # 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 image_annotator.AsyncBatchAnnotateFilesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, image_annotator.AsyncBatchAnnotateFilesRequest): - request = image_annotator.AsyncBatchAnnotateFilesRequest(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.async_batch_annotate_files] - - # 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, - image_annotator.AsyncBatchAnnotateFilesResponse, - metadata_type=image_annotator.OperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ImageAnnotatorClient", -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/__init__.py deleted file mode 100644 index 94f01250..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/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 ImageAnnotatorTransport -from .grpc import ImageAnnotatorGrpcTransport -from .grpc_asyncio import ImageAnnotatorGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ImageAnnotatorTransport]] -_transport_registry['grpc'] = ImageAnnotatorGrpcTransport -_transport_registry['grpc_asyncio'] = ImageAnnotatorGrpcAsyncIOTransport - -__all__ = ( - 'ImageAnnotatorTransport', - 'ImageAnnotatorGrpcTransport', - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py deleted file mode 100644 index 6c21970e..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/base.py +++ /dev/null @@ -1,247 +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.vision_v1p4beta1.types import image_annotator -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-vision', - ).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 ImageAnnotatorTransport(abc.ABC): - """Abstract transport class for ImageAnnotator.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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_annotate_images: gapic_v1.method.wrap_method( - self.batch_annotate_images, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.batch_annotate_files: gapic_v1.method.wrap_method( - self.batch_annotate_files, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.async_batch_annotate_images: gapic_v1.method.wrap_method( - self.async_batch_annotate_images, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.async_batch_annotate_files: gapic_v1.method.wrap_method( - self.async_batch_annotate_files, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def batch_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Union[ - image_annotator.BatchAnnotateImagesResponse, - Awaitable[image_annotator.BatchAnnotateImagesResponse] - ]]: - raise NotImplementedError() - - @property - def batch_annotate_files(self) -> Callable[ - [image_annotator.BatchAnnotateFilesRequest], - Union[ - image_annotator.BatchAnnotateFilesResponse, - Awaitable[image_annotator.BatchAnnotateFilesResponse] - ]]: - raise NotImplementedError() - - @property - def async_batch_annotate_images(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateImagesRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ImageAnnotatorTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py deleted file mode 100644 index 2aee2f9c..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc.py +++ /dev/null @@ -1,379 +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.vision_v1p4beta1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO - - -class ImageAnnotatorGrpcTransport(ImageAnnotatorTransport): - """gRPC backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - image_annotator.BatchAnnotateImagesResponse]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - ~.BatchAnnotateImagesResponse]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def batch_annotate_files(self) -> Callable[ - [image_annotator.BatchAnnotateFilesRequest], - image_annotator.BatchAnnotateFilesResponse]: - r"""Return a callable for the batch annotate files method over gRPC. - - Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Returns: - Callable[[~.BatchAnnotateFilesRequest], - ~.BatchAnnotateFilesResponse]: - 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_annotate_files' not in self._stubs: - self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateFiles', - request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, - ) - return self._stubs['batch_annotate_files'] - - @property - def async_batch_annotate_images(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateImagesRequest], - operations_pb2.Operation]: - r"""Return a callable for the async batch annotate images method over gRPC. - - Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Returns: - Callable[[~.AsyncBatchAnnotateImagesRequest], - ~.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 'async_batch_annotate_images' not in self._stubs: - self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages', - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - operations_pb2.Operation]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - ~.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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ImageAnnotatorGrpcTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py deleted file mode 100644 index 78ba0550..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/image_annotator/transports/grpc_asyncio.py +++ /dev/null @@ -1,384 +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.vision_v1p4beta1.types import image_annotator -from google.longrunning import operations_pb2 # type: ignore -from .base import ImageAnnotatorTransport, DEFAULT_CLIENT_INFO -from .grpc import ImageAnnotatorGrpcTransport - - -class ImageAnnotatorGrpcAsyncIOTransport(ImageAnnotatorTransport): - """gRPC AsyncIO backend transport for ImageAnnotator. - - Service that performs Google Cloud Vision API detection tasks - over client images, such as face, landmark, logo, label, and - text detection. The ImageAnnotator service returns detected - entities from the images. - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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_annotate_images(self) -> Callable[ - [image_annotator.BatchAnnotateImagesRequest], - Awaitable[image_annotator.BatchAnnotateImagesResponse]]: - r"""Return a callable for the batch annotate images method over gRPC. - - Run image detection and annotation for a batch of - images. - - Returns: - Callable[[~.BatchAnnotateImagesRequest], - Awaitable[~.BatchAnnotateImagesResponse]]: - 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_annotate_images' not in self._stubs: - self._stubs['batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateImages', - request_serializer=image_annotator.BatchAnnotateImagesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateImagesResponse.deserialize, - ) - return self._stubs['batch_annotate_images'] - - @property - def batch_annotate_files(self) -> Callable[ - [image_annotator.BatchAnnotateFilesRequest], - Awaitable[image_annotator.BatchAnnotateFilesResponse]]: - r"""Return a callable for the batch annotate files method over gRPC. - - Service that performs image detection and annotation - for a batch of files. Now only "application/pdf", - "image/tiff" and "image/gif" are supported. - This service will extract at most 5 (customers can - specify which 5 in AnnotateFileRequest.pages) frames - (gif) or pages (pdf or tiff) from each file provided and - perform detection and annotation for each image - extracted. - - Returns: - Callable[[~.BatchAnnotateFilesRequest], - Awaitable[~.BatchAnnotateFilesResponse]]: - 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_annotate_files' not in self._stubs: - self._stubs['batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateFiles', - request_serializer=image_annotator.BatchAnnotateFilesRequest.serialize, - response_deserializer=image_annotator.BatchAnnotateFilesResponse.deserialize, - ) - return self._stubs['batch_annotate_files'] - - @property - def async_batch_annotate_images(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateImagesRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the async batch annotate images method over gRPC. - - Run asynchronous image detection and annotation for a list of - images. - - Progress and results can be retrieved through the - ``google.longrunning.Operations`` interface. - ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateImagesResponse`` (results). - - This service will write image annotation outputs to json files - in customer GCS bucket, each json file containing - BatchAnnotateImagesResponse proto. - - Returns: - Callable[[~.AsyncBatchAnnotateImagesRequest], - 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 'async_batch_annotate_images' not in self._stubs: - self._stubs['async_batch_annotate_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateImages', - request_serializer=image_annotator.AsyncBatchAnnotateImagesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_images'] - - @property - def async_batch_annotate_files(self) -> Callable[ - [image_annotator.AsyncBatchAnnotateFilesRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the async batch annotate files method over gRPC. - - Run asynchronous image detection and annotation for a list of - generic files, such as PDF files, which may contain multiple - pages and multiple images per page. Progress and results can be - retrieved through the ``google.longrunning.Operations`` - interface. ``Operation.metadata`` contains ``OperationMetadata`` - (metadata). ``Operation.response`` contains - ``AsyncBatchAnnotateFilesResponse`` (results). - - Returns: - Callable[[~.AsyncBatchAnnotateFilesRequest], - 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 'async_batch_annotate_files' not in self._stubs: - self._stubs['async_batch_annotate_files'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ImageAnnotator/AsyncBatchAnnotateFiles', - request_serializer=image_annotator.AsyncBatchAnnotateFilesRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['async_batch_annotate_files'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ImageAnnotatorGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__init__.py deleted file mode 100644 index cf79a54d..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/__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 ProductSearchClient -from .async_client import ProductSearchAsyncClient - -__all__ = ( - 'ProductSearchClient', - 'ProductSearchAsyncClient', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py deleted file mode 100644 index 669c9459..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/async_client.py +++ /dev/null @@ -1,2095 +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.vision_v1p4beta1.services.product_search import pagers -from google.cloud.vision_v1p4beta1.types import geometry -from google.cloud.vision_v1p4beta1.types import product_search_service -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport -from .client import ProductSearchClient - - -class ProductSearchAsyncClient: - """Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - """ - - _client: ProductSearchClient - - DEFAULT_ENDPOINT = ProductSearchClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ProductSearchClient.DEFAULT_MTLS_ENDPOINT - - product_path = staticmethod(ProductSearchClient.product_path) - parse_product_path = staticmethod(ProductSearchClient.parse_product_path) - product_set_path = staticmethod(ProductSearchClient.product_set_path) - parse_product_set_path = staticmethod(ProductSearchClient.parse_product_set_path) - reference_image_path = staticmethod(ProductSearchClient.reference_image_path) - parse_reference_image_path = staticmethod(ProductSearchClient.parse_reference_image_path) - common_billing_account_path = staticmethod(ProductSearchClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductSearchClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ProductSearchClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductSearchClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductSearchClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductSearchClient.parse_common_organization_path) - common_project_path = staticmethod(ProductSearchClient.common_project_path) - parse_common_project_path = staticmethod(ProductSearchClient.parse_common_project_path) - common_location_path = staticmethod(ProductSearchClient.common_location_path) - parse_common_location_path = staticmethod(ProductSearchClient.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: - ProductSearchAsyncClient: The constructed client. - """ - return ProductSearchClient.from_service_account_info.__func__(ProductSearchAsyncClient, 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: - ProductSearchAsyncClient: The constructed client. - """ - return ProductSearchClient.from_service_account_file.__func__(ProductSearchAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ProductSearchTransport: - """Returns the transport used by the client instance. - - Returns: - ProductSearchTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(ProductSearchClient).get_transport_class, type(ProductSearchClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, ProductSearchTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product search 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, ~.ProductSearchTransport]): 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 = ProductSearchClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def create_product_set(self, - request: product_search_service.CreateProductSetRequest = None, - *, - parent: str = None, - product_set: product_search_service.ProductSet = None, - product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductSetRequest`): - The request object. Request message for the - `CreateProductSet` method. - parent (:class:`str`): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): - Required. The ProductSet to create. - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set_id (:class:`str`): - A user-supplied resource id for this ProductSet. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_set_id`` 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.vision_v1p4beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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, product_set, product_set_id]) - 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 = product_search_service.CreateProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product_set is not None: - request.product_set = product_set - if product_set_id is not None: - request.product_set_id = product_set_id - - # 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_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def list_product_sets(self, - request: product_search_service.ListProductSetsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductSetsAsyncPager: - r"""Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListProductSetsRequest`): - The request object. Request message for the - `ListProductSets` method. - parent (:class:`str`): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.vision_v1p4beta1.services.product_search.pagers.ListProductSetsAsyncPager: - Response message for the ListProductSets method. - - 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 = product_search_service.ListProductSetsRequest(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_product_sets, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductSetsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_product_set(self, - request: product_search_service.GetProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.GetProductSetRequest`): - The request object. Request message for the - `GetProductSet` method. - name (:class:`str`): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p4beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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 = product_search_service.GetProductSetRequest(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.get_product_set, - 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=600.0, - ), - default_timeout=600.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 update_product_set(self, - request: product_search_service.UpdateProductSetRequest = None, - *, - product_set: product_search_service.ProductSet = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest`): - The request object. Request message for the - `UpdateProductSet` method. - product_set (:class:`google.cloud.vision_v1p4beta1.types.ProductSet`): - Required. The ProductSet resource - which replaces the one on the server. - - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask path is ``display_name``. - - This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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([product_set, update_mask]) - 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 = product_search_service.UpdateProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_set is not None: - request.product_set = product_set - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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(( - ("product_set.name", request.product_set.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product_set(self, - request: product_search_service.DeleteProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest`): - The request object. Request message for the - `DeleteProductSet` method. - name (:class:`str`): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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. - """ - # 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 = product_search_service.DeleteProductSetRequest(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_product_set, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def create_product(self, - request: product_search_service.CreateProductRequest = None, - *, - parent: str = None, - product: product_search_service.Product = None, - product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.CreateProductRequest`): - The request object. Request message for the - `CreateProduct` method. - parent (:class:`str`): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`google.cloud.vision_v1p4beta1.types.Product`): - Required. The product to create. - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_id (:class:`str`): - A user-supplied resource id for this Product. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_id`` 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.vision_v1p4beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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, product, product_id]) - 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 = product_search_service.CreateProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product is not None: - request.product = product - if product_id is not None: - request.product_id = product_id - - # 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_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def list_products(self, - request: product_search_service.ListProductsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsAsyncPager: - r"""Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsRequest`): - The request object. Request message for the - `ListProducts` method. - parent (:class:`str`): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - - 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.vision_v1p4beta1.services.product_search.pagers.ListProductsAsyncPager: - Response message for the ListProducts method. - - 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 = product_search_service.ListProductsRequest(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_products, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_product(self, - request: product_search_service.GetProductRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.GetProductRequest`): - The request object. Request message for the `GetProduct` - method. - name (:class:`str`): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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.vision_v1p4beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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 = product_search_service.GetProductRequest(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.get_product, - 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=600.0, - ), - default_timeout=600.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 update_product(self, - request: product_search_service.UpdateProductRequest = None, - *, - product: product_search_service.Product = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.UpdateProductRequest`): - The request object. Request message for the - `UpdateProduct` method. - product (:class:`google.cloud.vision_v1p4beta1.types.Product`): - Required. The Product resource which - replaces the one on the server. - product.name is immutable. - - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask paths include ``product_labels``, ``display_name``, - and ``description``. - - This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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([product, update_mask]) - 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 = product_search_service.UpdateProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product is not None: - request.product = product - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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(( - ("product.name", request.product.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product(self, - request: product_search_service.DeleteProductRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.DeleteProductRequest`): - The request object. Request message for the - `DeleteProduct` method. - name (:class:`str`): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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. - """ - # 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 = product_search_service.DeleteProductRequest(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_product, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def create_reference_image(self, - request: product_search_service.CreateReferenceImageRequest = None, - *, - parent: str = None, - reference_image: product_search_service.ReferenceImage = None, - reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest`): - The request object. Request message for the - `CreateReferenceImage` method. - parent (:class:`str`): - Required. Resource name of the product in which to - create the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image (:class:`google.cloud.vision_v1p4beta1.types.ReferenceImage`): - Required. The reference image to - create. If an image ID is specified, it - is ignored. - - This corresponds to the ``reference_image`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image_id (:class:`str`): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value - as the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``reference_image_id`` 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.vision_v1p4beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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, reference_image, reference_image_id]) - 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 = product_search_service.CreateReferenceImageRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if reference_image is not None: - request.reference_image = reference_image - if reference_image_id is not None: - request.reference_image_id = reference_image_id - - # 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_reference_image, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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 - - async def delete_reference_image(self, - request: product_search_service.DeleteReferenceImageRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest`): - The request object. Request message for the - `DeleteReferenceImage` method. - name (:class:`str`): - Required. The resource name of the reference image to - delete. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - - 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. - """ - # 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 = product_search_service.DeleteReferenceImageRequest(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_reference_image, - 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=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_reference_images(self, - request: product_search_service.ListReferenceImagesRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListReferenceImagesAsyncPager: - r"""Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest`): - The request object. Request message for the - `ListReferenceImages` method. - parent (:class:`str`): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - 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.vision_v1p4beta1.services.product_search.pagers.ListReferenceImagesAsyncPager: - Response message for the ListReferenceImages method. - - 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 = product_search_service.ListReferenceImagesRequest(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_reference_images, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListReferenceImagesAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_reference_image(self, - request: product_search_service.GetReferenceImageRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest`): - The request object. Request message for the - `GetReferenceImage` method. - name (:class:`str`): - Required. The resource name of the ReferenceImage to - get. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - 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.vision_v1p4beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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 = product_search_service.GetReferenceImageRequest(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.get_reference_image, - 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=600.0, - ), - default_timeout=600.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 add_product_to_product_set(self, - request: product_search_service.AddProductToProductSetRequest = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest`): - The request object. Request message for the - `AddProductToProductSet` method. - name (:class:`str`): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`str`): - Required. The resource name for the Product to be added - to this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 = product_search_service.AddProductToProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.add_product_to_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def remove_product_from_product_set(self, - request: product_search_service.RemoveProductFromProductSetRequest = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Removes a Product from the specified ProductSet. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest`): - The request object. Request message for the - `RemoveProductFromProductSet` method. - name (:class:`str`): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (:class:`str`): - Required. The resource name for the Product to be - removed from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 = product_search_service.RemoveProductFromProductSetRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.remove_product_from_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_products_in_product_set(self, - request: product_search_service.ListProductsInProductSetRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsInProductSetAsyncPager: - r"""Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest`): - The request object. Request message for the - `ListProductsInProductSet` method. - name (:class:`str`): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p4beta1.services.product_search.pagers.ListProductsInProductSetAsyncPager: - Response message for the ListProductsInProductSet - method. - - 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([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 = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set, - 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=600.0, - ), - default_timeout=600.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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsInProductSetAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def import_product_sets(self, - request: product_search_service.ImportProductSetsRequest = None, - *, - parent: str = None, - input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest`): - The request object. Request message for the - `ImportProductSets` method. - parent (:class:`str`): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - input_config (:class:`google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig`): - Required. The input content for the - list of requests. - - This corresponds to the ``input_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.vision_v1p4beta1.types.ImportProductSetsResponse` - Response message for the ImportProductSets method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - """ - # 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, input_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 = product_search_service.ImportProductSetsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if input_config is not None: - request.input_config = input_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.import_product_sets, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.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, - product_search_service.ImportProductSetsResponse, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - async def purge_products(self, - request: product_search_service.PurgeProductsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Args: - request (:class:`google.cloud.vision_v1p4beta1.types.PurgeProductsRequest`): - The request object. Request message for the - `PurgeProducts` method. - parent (:class:`str`): - Required. The project and location in which the Products - should be deleted. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.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([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 = product_search_service.PurgeProductsRequest(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.purge_products, - 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, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - empty_pb2.Empty, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ProductSearchAsyncClient", -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py deleted file mode 100644 index 4449ccfd..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/client.py +++ /dev/null @@ -1,2200 +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 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.vision_v1p4beta1.services.product_search import pagers -from google.cloud.vision_v1p4beta1.types import geometry -from google.cloud.vision_v1p4beta1.types import product_search_service -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ProductSearchGrpcTransport -from .transports.grpc_asyncio import ProductSearchGrpcAsyncIOTransport - - -class ProductSearchClientMeta(type): - """Metaclass for the ProductSearch 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[ProductSearchTransport]] - _transport_registry["grpc"] = ProductSearchGrpcTransport - _transport_registry["grpc_asyncio"] = ProductSearchGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[ProductSearchTransport]: - """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 ProductSearchClient(metaclass=ProductSearchClientMeta): - """Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - """ - - @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 = "vision.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: - ProductSearchClient: 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: - ProductSearchClient: 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) -> ProductSearchTransport: - """Returns the transport used by the client instance. - - Returns: - ProductSearchTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(project: str,location: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_set_path(project: str,location: str,product_set: str,) -> str: - """Returns a fully-qualified product_set string.""" - return "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - - @staticmethod - def parse_product_set_path(path: str) -> Dict[str,str]: - """Parses a product_set path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/productSets/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def reference_image_path(project: str,location: str,product: str,reference_image: str,) -> str: - """Returns a fully-qualified reference_image string.""" - return "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) - - @staticmethod - def parse_reference_image_path(path: str) -> Dict[str,str]: - """Parses a reference_image path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/products/(?P.+?)/referenceImages/(?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, ProductSearchTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product search 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, ProductSearchTransport]): 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, ProductSearchTransport): - # transport is a ProductSearchTransport 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, - always_use_jwt_access=True, - ) - - def create_product_set(self, - request: Union[product_search_service.CreateProductSetRequest, dict] = None, - *, - parent: str = None, - product_set: product_search_service.ProductSet = None, - product_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.CreateProductSetRequest, dict]): - The request object. Request message for the - `CreateProductSet` method. - parent (str): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set (google.cloud.vision_v1p4beta1.types.ProductSet): - Required. The ProductSet to create. - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_set_id (str): - A user-supplied resource id for this ProductSet. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_set_id`` 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.vision_v1p4beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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, product_set, product_set_id]) - 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 product_search_service.CreateProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateProductSetRequest): - request = product_search_service.CreateProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product_set is not None: - request.product_set = product_set - if product_set_id is not None: - request.product_set_id = product_set_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_product_set] - - # 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_product_sets(self, - request: Union[product_search_service.ListProductSetsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductSetsPager: - r"""Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.ListProductSetsRequest, dict]): - The request object. Request message for the - `ListProductSets` method. - parent (str): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.vision_v1p4beta1.services.product_search.pagers.ListProductSetsPager: - Response message for the ListProductSets method. - - 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 product_search_service.ListProductSetsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductSetsRequest): - request = product_search_service.ListProductSetsRequest(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_product_sets] - - # 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.ListProductSetsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_product_set(self, - request: Union[product_search_service.GetProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.GetProductSetRequest, dict]): - The request object. Request message for the - `GetProductSet` method. - name (str): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p4beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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 product_search_service.GetProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetProductSetRequest): - request = product_search_service.GetProductSetRequest(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.get_product_set] - - # 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 update_product_set(self, - request: Union[product_search_service.UpdateProductSetRequest, dict] = None, - *, - product_set: product_search_service.ProductSet = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ProductSet: - r"""Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductSetRequest, dict]): - The request object. Request message for the - `UpdateProductSet` method. - product_set (google.cloud.vision_v1p4beta1.types.ProductSet): - Required. The ProductSet resource - which replaces the one on the server. - - This corresponds to the ``product_set`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask path is ``display_name``. - - This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.ProductSet: - A ProductSet contains Products. A - ProductSet can contain a maximum of 1 - million reference images. If the limit - is exceeded, periodic indexing will - fail. - - """ - # 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([product_set, update_mask]) - 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 product_search_service.UpdateProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.UpdateProductSetRequest): - request = product_search_service.UpdateProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_set is not None: - request.product_set = product_set - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product_set] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_set.name", request.product_set.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product_set(self, - request: Union[product_search_service.DeleteProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductSetRequest, dict]): - The request object. Request message for the - `DeleteProductSet` method. - name (str): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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. - """ - # 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 product_search_service.DeleteProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteProductSetRequest): - request = product_search_service.DeleteProductSetRequest(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_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def create_product(self, - request: Union[product_search_service.CreateProductRequest, dict] = None, - *, - parent: str = None, - product: product_search_service.Product = None, - product_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.CreateProductRequest, dict]): - The request object. Request message for the - `CreateProduct` method. - parent (str): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (google.cloud.vision_v1p4beta1.types.Product): - Required. The product to create. - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product_id (str): - A user-supplied resource id for this Product. If set, - the server will attempt to use this value as the - resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``product_id`` 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.vision_v1p4beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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, product, product_id]) - 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 product_search_service.CreateProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateProductRequest): - request = product_search_service.CreateProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if product is not None: - request.product = product - if product_id is not None: - request.product_id = product_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_product] - - # 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_products(self, - request: Union[product_search_service.ListProductsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsPager: - r"""Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.ListProductsRequest, dict]): - The request object. Request message for the - `ListProducts` method. - parent (str): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - - 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.vision_v1p4beta1.services.product_search.pagers.ListProductsPager: - Response message for the ListProducts method. - - 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 product_search_service.ListProductsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductsRequest): - request = product_search_service.ListProductsRequest(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_products] - - # 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.ListProductsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_product(self, - request: Union[product_search_service.GetProductRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.GetProductRequest, dict]): - The request object. Request message for the `GetProduct` - method. - name (str): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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.vision_v1p4beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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 product_search_service.GetProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetProductRequest): - request = product_search_service.GetProductRequest(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.get_product] - - # 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 update_product(self, - request: Union[product_search_service.UpdateProductRequest, dict] = None, - *, - product: product_search_service.Product = None, - update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.Product: - r"""Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.UpdateProductRequest, dict]): - The request object. Request message for the - `UpdateProduct` method. - product (google.cloud.vision_v1p4beta1.types.Product): - Required. The Product resource which - replaces the one on the server. - product.name is immutable. - - This corresponds to the ``product`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that - specifies which fields to update. If update_mask isn't - specified, all mutable fields are to be updated. Valid - mask paths include ``product_labels``, ``display_name``, - and ``description``. - - This corresponds to the ``update_mask`` 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.vision_v1p4beta1.types.Product: - A Product contains ReferenceImages. - """ - # 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([product, update_mask]) - 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 product_search_service.UpdateProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.UpdateProductRequest): - request = product_search_service.UpdateProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product is not None: - request.product = product - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product.name", request.product.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product(self, - request: Union[product_search_service.DeleteProductRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.DeleteProductRequest, dict]): - The request object. Request message for the - `DeleteProduct` method. - name (str): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - 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. - """ - # 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 product_search_service.DeleteProductRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteProductRequest): - request = product_search_service.DeleteProductRequest(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_product] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def create_reference_image(self, - request: Union[product_search_service.CreateReferenceImageRequest, dict] = None, - *, - parent: str = None, - reference_image: product_search_service.ReferenceImage = None, - reference_image_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.CreateReferenceImageRequest, dict]): - The request object. Request message for the - `CreateReferenceImage` method. - parent (str): - Required. Resource name of the product in which to - create the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image (google.cloud.vision_v1p4beta1.types.ReferenceImage): - Required. The reference image to - create. If an image ID is specified, it - is ignored. - - This corresponds to the ``reference_image`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - reference_image_id (str): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value - as the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - - This corresponds to the ``reference_image_id`` 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.vision_v1p4beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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, reference_image, reference_image_id]) - 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 product_search_service.CreateReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.CreateReferenceImageRequest): - request = product_search_service.CreateReferenceImageRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if reference_image is not None: - request.reference_image = reference_image - if reference_image_id is not None: - request.reference_image_id = reference_image_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_reference_image] - - # 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_reference_image(self, - request: Union[product_search_service.DeleteReferenceImageRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.DeleteReferenceImageRequest, dict]): - The request object. Request message for the - `DeleteReferenceImage` method. - name (str): - Required. The resource name of the reference image to - delete. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - - 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. - """ - # 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 product_search_service.DeleteReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.DeleteReferenceImageRequest): - request = product_search_service.DeleteReferenceImageRequest(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_reference_image] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_reference_images(self, - request: Union[product_search_service.ListReferenceImagesRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListReferenceImagesPager: - r"""Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.ListReferenceImagesRequest, dict]): - The request object. Request message for the - `ListReferenceImages` method. - parent (str): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - 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.vision_v1p4beta1.services.product_search.pagers.ListReferenceImagesPager: - Response message for the ListReferenceImages method. - - 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 product_search_service.ListReferenceImagesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListReferenceImagesRequest): - request = product_search_service.ListReferenceImagesRequest(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_reference_images] - - # 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.ListReferenceImagesPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_reference_image(self, - request: Union[product_search_service.GetReferenceImageRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> product_search_service.ReferenceImage: - r"""Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.GetReferenceImageRequest, dict]): - The request object. Request message for the - `GetReferenceImage` method. - name (str): - Required. The resource name of the ReferenceImage to - get. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - 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.vision_v1p4beta1.types.ReferenceImage: - A ReferenceImage represents a product image and its associated metadata, - such as bounding boxes. - - """ - # 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 product_search_service.GetReferenceImageRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.GetReferenceImageRequest): - request = product_search_service.GetReferenceImageRequest(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.get_reference_image] - - # 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 add_product_to_product_set(self, - request: Union[product_search_service.AddProductToProductSetRequest, dict] = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.AddProductToProductSetRequest, dict]): - The request object. Request message for the - `AddProductToProductSet` method. - name (str): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (str): - Required. The resource name for the Product to be added - to this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 product_search_service.AddProductToProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.AddProductToProductSetRequest): - request = product_search_service.AddProductToProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.add_product_to_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def remove_product_from_product_set(self, - request: Union[product_search_service.RemoveProductFromProductSetRequest, dict] = None, - *, - name: str = None, - product: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Removes a Product from the specified ProductSet. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.RemoveProductFromProductSetRequest, dict]): - The request object. Request message for the - `RemoveProductFromProductSet` method. - name (str): - Required. The resource name for the ProductSet to - modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - product (str): - Required. The resource name for the Product to be - removed from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - - This corresponds to the ``product`` 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. - """ - # 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, product]) - 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 product_search_service.RemoveProductFromProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.RemoveProductFromProductSetRequest): - request = product_search_service.RemoveProductFromProductSetRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - if product is not None: - request.product = product - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.remove_product_from_product_set] - - # 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. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_products_in_product_set(self, - request: Union[product_search_service.ListProductsInProductSetRequest, dict] = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProductsInProductSetPager: - r"""Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.ListProductsInProductSetRequest, dict]): - The request object. Request message for the - `ListProductsInProductSet` method. - name (str): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - - 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.vision_v1p4beta1.services.product_search.pagers.ListProductsInProductSetPager: - Response message for the ListProductsInProductSet - method. - - 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([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 product_search_service.ListProductsInProductSetRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ListProductsInProductSetRequest): - request = product_search_service.ListProductsInProductSetRequest(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.list_products_in_product_set] - - # 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, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListProductsInProductSetPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def import_product_sets(self, - request: Union[product_search_service.ImportProductSetsRequest, dict] = None, - *, - parent: str = None, - input_config: product_search_service.ImportProductSetsInputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.ImportProductSetsRequest, dict]): - The request object. Request message for the - `ImportProductSets` method. - parent (str): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - input_config (google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig): - Required. The input content for the - list of requests. - - This corresponds to the ``input_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.vision_v1p4beta1.types.ImportProductSetsResponse` - Response message for the ImportProductSets method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - """ - # 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, input_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 product_search_service.ImportProductSetsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.ImportProductSetsRequest): - request = product_search_service.ImportProductSetsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if input_config is not None: - request.input_config = input_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.import_product_sets] - - # 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, - product_search_service.ImportProductSetsResponse, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - def purge_products(self, - request: Union[product_search_service.PurgeProductsRequest, dict] = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Args: - request (Union[google.cloud.vision_v1p4beta1.types.PurgeProductsRequest, dict]): - The request object. Request message for the - `PurgeProducts` method. - parent (str): - Required. The project and location in which the Products - should be deleted. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - - 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.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([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 product_search_service.PurgeProductsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, product_search_service.PurgeProductsRequest): - request = product_search_service.PurgeProductsRequest(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.purge_products] - - # 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, - empty_pb2.Empty, - metadata_type=product_search_service.BatchOperationMetadata, - ) - - # Done; return the response. - return response - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-vision", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "ProductSearchClient", -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py deleted file mode 100644 index f4e931a2..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/pagers.py +++ /dev/null @@ -1,506 +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, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator - -from google.cloud.vision_v1p4beta1.types import product_search_service - - -class ListProductSetsPager: - """A pager for iterating through ``list_product_sets`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``product_sets`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProductSets`` requests and continue to iterate - through the ``product_sets`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` - 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[..., product_search_service.ListProductSetsResponse], - request: product_search_service.ListProductSetsRequest, - response: product_search_service.ListProductSetsResponse, - *, - 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.vision_v1p4beta1.types.ListProductSetsRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListProductSetsResponse): - 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 = product_search_service.ListProductSetsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductSetsResponse]: - 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) -> Iterator[product_search_service.ProductSet]: - for page in self.pages: - yield from page.product_sets - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductSetsAsyncPager: - """A pager for iterating through ``list_product_sets`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``product_sets`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProductSets`` requests and continue to iterate - through the ``product_sets`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductSetsResponse` - 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[product_search_service.ListProductSetsResponse]], - request: product_search_service.ListProductSetsRequest, - response: product_search_service.ListProductSetsResponse, - *, - 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.vision_v1p4beta1.types.ListProductSetsRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListProductSetsResponse): - 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 = product_search_service.ListProductSetsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductSetsResponse]: - 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) -> AsyncIterator[product_search_service.ProductSet]: - async def async_generator(): - async for page in self.pages: - for response in page.product_sets: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` - 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[..., product_search_service.ListProductsResponse], - request: product_search_service.ListProductsRequest, - response: product_search_service.ListProductsResponse, - *, - 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.vision_v1p4beta1.types.ListProductsRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListProductsResponse): - 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 = product_search_service.ListProductsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductsResponse]: - 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) -> Iterator[product_search_service.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsAsyncPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsResponse` - 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[product_search_service.ListProductsResponse]], - request: product_search_service.ListProductsRequest, - response: product_search_service.ListProductsResponse, - *, - 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.vision_v1p4beta1.types.ListProductsRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListProductsResponse): - 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 = product_search_service.ListProductsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductsResponse]: - 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) -> AsyncIterator[product_search_service.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListReferenceImagesPager: - """A pager for iterating through ``list_reference_images`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` object, and - provides an ``__iter__`` method to iterate through its - ``reference_images`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListReferenceImages`` requests and continue to iterate - through the ``reference_images`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` - 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[..., product_search_service.ListReferenceImagesResponse], - request: product_search_service.ListReferenceImagesRequest, - response: product_search_service.ListReferenceImagesResponse, - *, - 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.vision_v1p4beta1.types.ListReferenceImagesRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse): - 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 = product_search_service.ListReferenceImagesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListReferenceImagesResponse]: - 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) -> Iterator[product_search_service.ReferenceImage]: - for page in self.pages: - yield from page.reference_images - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListReferenceImagesAsyncPager: - """A pager for iterating through ``list_reference_images`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``reference_images`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListReferenceImages`` requests and continue to iterate - through the ``reference_images`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse` - 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[product_search_service.ListReferenceImagesResponse]], - request: product_search_service.ListReferenceImagesRequest, - response: product_search_service.ListReferenceImagesResponse, - *, - 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.vision_v1p4beta1.types.ListReferenceImagesRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListReferenceImagesResponse): - 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 = product_search_service.ListReferenceImagesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListReferenceImagesResponse]: - 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) -> AsyncIterator[product_search_service.ReferenceImage]: - async def async_generator(): - async for page in self.pages: - for response in page.reference_images: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsInProductSetPager: - """A pager for iterating through ``list_products_in_product_set`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProductsInProductSet`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` - 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[..., product_search_service.ListProductsInProductSetResponse], - request: product_search_service.ListProductsInProductSetRequest, - response: product_search_service.ListProductsInProductSetResponse, - *, - 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.vision_v1p4beta1.types.ListProductsInProductSetRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse): - 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 = product_search_service.ListProductsInProductSetRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[product_search_service.ListProductsInProductSetResponse]: - 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) -> Iterator[product_search_service.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsInProductSetAsyncPager: - """A pager for iterating through ``list_products_in_product_set`` requests. - - This class thinly wraps an initial - :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProductsInProductSet`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse` - 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[product_search_service.ListProductsInProductSetResponse]], - request: product_search_service.ListProductsInProductSetRequest, - response: product_search_service.ListProductsInProductSetResponse, - *, - 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.vision_v1p4beta1.types.ListProductsInProductSetRequest): - The initial request object. - response (google.cloud.vision_v1p4beta1.types.ListProductsInProductSetResponse): - 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 = product_search_service.ListProductsInProductSetRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[product_search_service.ListProductsInProductSetResponse]: - 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) -> AsyncIterator[product_search_service.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - 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/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/__init__.py deleted file mode 100644 index 22b20282..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/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 ProductSearchTransport -from .grpc import ProductSearchGrpcTransport -from .grpc_asyncio import ProductSearchGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ProductSearchTransport]] -_transport_registry['grpc'] = ProductSearchGrpcTransport -_transport_registry['grpc_asyncio'] = ProductSearchGrpcAsyncIOTransport - -__all__ = ( - 'ProductSearchTransport', - 'ProductSearchGrpcTransport', - 'ProductSearchGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py deleted file mode 100644 index be52431c..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/base.py +++ /dev/null @@ -1,548 +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.vision_v1p4beta1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-vision', - ).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 ProductSearchTransport(abc.ABC): - """Abstract transport class for ProductSearch.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ) - - DEFAULT_HOST: str = 'vision.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 are 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.create_product_set: gapic_v1.method.wrap_method( - self.create_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_product_sets: gapic_v1.method.wrap_method( - self.list_product_sets, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_product_set: gapic_v1.method.wrap_method( - self.get_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.update_product_set: gapic_v1.method.wrap_method( - self.update_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_product_set: gapic_v1.method.wrap_method( - self.delete_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.create_product: gapic_v1.method.wrap_method( - self.create_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_products: gapic_v1.method.wrap_method( - self.list_products, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_product: gapic_v1.method.wrap_method( - self.get_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.update_product: gapic_v1.method.wrap_method( - self.update_product, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_product: gapic_v1.method.wrap_method( - self.delete_product, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.create_reference_image: gapic_v1.method.wrap_method( - self.create_reference_image, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.delete_reference_image: gapic_v1.method.wrap_method( - self.delete_reference_image, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_reference_images: gapic_v1.method.wrap_method( - self.list_reference_images, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.get_reference_image: gapic_v1.method.wrap_method( - self.get_reference_image, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.add_product_to_product_set: gapic_v1.method.wrap_method( - self.add_product_to_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.remove_product_from_product_set: gapic_v1.method.wrap_method( - self.remove_product_from_product_set, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.list_products_in_product_set: gapic_v1.method.wrap_method( - self.list_products_in_product_set, - 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=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.import_product_sets: gapic_v1.method.wrap_method( - self.import_product_sets, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - ), - deadline=600.0, - ), - default_timeout=600.0, - client_info=client_info, - ), - self.purge_products: gapic_v1.method.wrap_method( - self.purge_products, - default_timeout=None, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - Union[ - product_search_service.ListProductSetsResponse, - Awaitable[product_search_service.ListProductSetsResponse] - ]]: - raise NotImplementedError() - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - Union[ - product_search_service.ProductSet, - Awaitable[product_search_service.ProductSet] - ]]: - raise NotImplementedError() - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - Union[ - product_search_service.ListProductsResponse, - Awaitable[product_search_service.ListProductsResponse] - ]]: - raise NotImplementedError() - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - Union[ - product_search_service.Product, - Awaitable[product_search_service.Product] - ]]: - raise NotImplementedError() - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - Union[ - product_search_service.ReferenceImage, - Awaitable[product_search_service.ReferenceImage] - ]]: - raise NotImplementedError() - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - Union[ - product_search_service.ListReferenceImagesResponse, - Awaitable[product_search_service.ListReferenceImagesResponse] - ]]: - raise NotImplementedError() - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - Union[ - product_search_service.ReferenceImage, - Awaitable[product_search_service.ReferenceImage] - ]]: - raise NotImplementedError() - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - Union[ - product_search_service.ListProductsInProductSetResponse, - Awaitable[product_search_service.ListProductsInProductSetResponse] - ]]: - raise NotImplementedError() - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def purge_products(self) -> Callable[ - [product_search_service.PurgeProductsRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'ProductSearchTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py deleted file mode 100644 index 928fa867..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc.py +++ /dev/null @@ -1,914 +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.vision_v1p4beta1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO - - -class ProductSearchGrpcTransport(ProductSearchTransport): - """gRPC backend transport for ProductSearch. - - Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - - 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 = 'vision.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 application 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 the 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 a 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 = 'vision.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 create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the create product set method over gRPC. - - Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Returns: - Callable[[~.CreateProductSetRequest], - ~.ProductSet]: - 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_product_set' not in self._stubs: - self._stubs['create_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProductSet', - request_serializer=product_search_service.CreateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['create_product_set'] - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - product_search_service.ListProductSetsResponse]: - r"""Return a callable for the list product sets method over gRPC. - - Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Returns: - Callable[[~.ListProductSetsRequest], - ~.ListProductSetsResponse]: - 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_product_sets' not in self._stubs: - self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductSets', - request_serializer=product_search_service.ListProductSetsRequest.serialize, - response_deserializer=product_search_service.ListProductSetsResponse.deserialize, - ) - return self._stubs['list_product_sets'] - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the get product set method over gRPC. - - Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.GetProductSetRequest], - ~.ProductSet]: - 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 'get_product_set' not in self._stubs: - self._stubs['get_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/GetProductSet', - request_serializer=product_search_service.GetProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['get_product_set'] - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - product_search_service.ProductSet]: - r"""Return a callable for the update product set method over gRPC. - - Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Returns: - Callable[[~.UpdateProductSetRequest], - ~.ProductSet]: - 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 'update_product_set' not in self._stubs: - self._stubs['update_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProductSet', - request_serializer=product_search_service.UpdateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['update_product_set'] - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product set method over gRPC. - - Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteProductSetRequest], - ~.Empty]: - 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_product_set' not in self._stubs: - self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProductSet', - request_serializer=product_search_service.DeleteProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_set'] - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - product_search_service.Product]: - r"""Return a callable for the create product method over gRPC. - - Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Returns: - Callable[[~.CreateProductRequest], - ~.Product]: - 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_product' not in self._stubs: - self._stubs['create_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProduct', - request_serializer=product_search_service.CreateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['create_product'] - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - product_search_service.ListProductsResponse]: - r"""Return a callable for the list products method over gRPC. - - Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsRequest], - ~.ListProductsResponse]: - 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_products' not in self._stubs: - self._stubs['list_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListProducts', - request_serializer=product_search_service.ListProductsRequest.serialize, - response_deserializer=product_search_service.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - product_search_service.Product]: - r"""Return a callable for the get product method over gRPC. - - Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns: - Callable[[~.GetProductRequest], - ~.Product]: - 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 'get_product' not in self._stubs: - self._stubs['get_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/GetProduct', - request_serializer=product_search_service.GetProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - product_search_service.Product]: - r"""Return a callable for the update product method over gRPC. - - Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Returns: - Callable[[~.UpdateProductRequest], - ~.Product]: - 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 'update_product' not in self._stubs: - self._stubs['update_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProduct', - request_serializer=product_search_service.UpdateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['update_product'] - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product method over gRPC. - - Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Returns: - Callable[[~.DeleteProductRequest], - ~.Empty]: - 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_product' not in self._stubs: - self._stubs['delete_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProduct', - request_serializer=product_search_service.DeleteProductRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product'] - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - product_search_service.ReferenceImage]: - r"""Return a callable for the create reference image method over gRPC. - - Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Returns: - Callable[[~.CreateReferenceImageRequest], - ~.ReferenceImage]: - 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_reference_image' not in self._stubs: - self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/CreateReferenceImage', - request_serializer=product_search_service.CreateReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['create_reference_image'] - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete reference image method over gRPC. - - Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteReferenceImageRequest], - ~.Empty]: - 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_reference_image' not in self._stubs: - self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteReferenceImage', - request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_reference_image'] - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - product_search_service.ListReferenceImagesResponse]: - r"""Return a callable for the list reference images method over gRPC. - - Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Returns: - Callable[[~.ListReferenceImagesRequest], - ~.ListReferenceImagesResponse]: - 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_reference_images' not in self._stubs: - self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListReferenceImages', - request_serializer=product_search_service.ListReferenceImagesRequest.serialize, - response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, - ) - return self._stubs['list_reference_images'] - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - product_search_service.ReferenceImage]: - r"""Return a callable for the get reference image method over gRPC. - - Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Returns: - Callable[[~.GetReferenceImageRequest], - ~.ReferenceImage]: - 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 'get_reference_image' not in self._stubs: - self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/GetReferenceImage', - request_serializer=product_search_service.GetReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['get_reference_image'] - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the add product to product set method over gRPC. - - Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Returns: - Callable[[~.AddProductToProductSetRequest], - ~.Empty]: - 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 'add_product_to_product_set' not in self._stubs: - self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet', - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['add_product_to_product_set'] - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - empty_pb2.Empty]: - r"""Return a callable for the remove product from product - set method over gRPC. - - Removes a Product from the specified ProductSet. - - Returns: - Callable[[~.RemoveProductFromProductSetRequest], - ~.Empty]: - 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 'remove_product_from_product_set' not in self._stubs: - self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet', - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['remove_product_from_product_set'] - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - product_search_service.ListProductsInProductSetResponse]: - r"""Return a callable for the list products in product set method over gRPC. - - Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsInProductSetRequest], - ~.ListProductsInProductSetResponse]: - 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_products_in_product_set' not in self._stubs: - self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet', - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, - ) - return self._stubs['list_products_in_product_set'] - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - operations_pb2.Operation]: - r"""Return a callable for the import product sets method over gRPC. - - Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Returns: - Callable[[~.ImportProductSetsRequest], - ~.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 'import_product_sets' not in self._stubs: - self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ImportProductSets', - request_serializer=product_search_service.ImportProductSetsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['import_product_sets'] - - @property - def purge_products(self) -> Callable[ - [product_search_service.PurgeProductsRequest], - operations_pb2.Operation]: - r"""Return a callable for the purge products method over gRPC. - - Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Returns: - Callable[[~.PurgeProductsRequest], - ~.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 'purge_products' not in self._stubs: - self._stubs['purge_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/PurgeProducts', - request_serializer=product_search_service.PurgeProductsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['purge_products'] - - def close(self): - self.grpc_channel.close() - -__all__ = ( - 'ProductSearchGrpcTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py deleted file mode 100644 index 0778fe9b..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/services/product_search/transports/grpc_asyncio.py +++ /dev/null @@ -1,919 +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.vision_v1p4beta1.types import product_search_service -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import ProductSearchTransport, DEFAULT_CLIENT_INFO -from .grpc import ProductSearchGrpcTransport - - -class ProductSearchGrpcAsyncIOTransport(ProductSearchTransport): - """gRPC AsyncIO backend transport for ProductSearch. - - Manages Products and ProductSets of reference images for use in - product search. It uses the following resource model: - - - The API has a collection of - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] resources, - named ``projects/*/locations/*/productSets/*``, which acts as a - way to put different products into groups to limit - identification. - - In parallel, - - - The API has a collection of - [Product][google.cloud.vision.v1p4beta1.Product] resources, named - ``projects/*/locations/*/products/*`` - - - Each [Product][google.cloud.vision.v1p4beta1.Product] has a - collection of - [ReferenceImage][google.cloud.vision.v1p4beta1.ReferenceImage] - resources, named - ``projects/*/locations/*/products/*/referenceImages/*`` - - 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 = 'vision.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 = 'vision.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 application 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 the 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 a 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 create_product_set(self) -> Callable[ - [product_search_service.CreateProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the create product set method over gRPC. - - Creates and returns a new ProductSet resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing, or is - longer than 4096 characters. - - Returns: - Callable[[~.CreateProductSetRequest], - Awaitable[~.ProductSet]]: - 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_product_set' not in self._stubs: - self._stubs['create_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProductSet', - request_serializer=product_search_service.CreateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['create_product_set'] - - @property - def list_product_sets(self) -> Callable[ - [product_search_service.ListProductSetsRequest], - Awaitable[product_search_service.ListProductSetsResponse]]: - r"""Return a callable for the list product sets method over gRPC. - - Lists ProductSets in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100, or - less than 1. - - Returns: - Callable[[~.ListProductSetsRequest], - Awaitable[~.ListProductSetsResponse]]: - 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_product_sets' not in self._stubs: - self._stubs['list_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductSets', - request_serializer=product_search_service.ListProductSetsRequest.serialize, - response_deserializer=product_search_service.ListProductSetsResponse.deserialize, - ) - return self._stubs['list_product_sets'] - - @property - def get_product_set(self) -> Callable[ - [product_search_service.GetProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the get product set method over gRPC. - - Gets information associated with a ProductSet. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns: - Callable[[~.GetProductSetRequest], - Awaitable[~.ProductSet]]: - 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 'get_product_set' not in self._stubs: - self._stubs['get_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/GetProductSet', - request_serializer=product_search_service.GetProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['get_product_set'] - - @property - def update_product_set(self) -> Callable[ - [product_search_service.UpdateProductSetRequest], - Awaitable[product_search_service.ProductSet]]: - r"""Return a callable for the update product set method over gRPC. - - Makes changes to a ProductSet resource. Only display_name can be - updated currently. - - Possible errors: - - - Returns NOT_FOUND if the ProductSet does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but missing from the request or longer than 4096 - characters. - - Returns: - Callable[[~.UpdateProductSetRequest], - Awaitable[~.ProductSet]]: - 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 'update_product_set' not in self._stubs: - self._stubs['update_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProductSet', - request_serializer=product_search_service.UpdateProductSetRequest.serialize, - response_deserializer=product_search_service.ProductSet.deserialize, - ) - return self._stubs['update_product_set'] - - @property - def delete_product_set(self) -> Callable[ - [product_search_service.DeleteProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product set method over gRPC. - - Permanently deletes a ProductSet. Products and - ReferenceImages in the ProductSet are not deleted. - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteProductSetRequest], - Awaitable[~.Empty]]: - 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_product_set' not in self._stubs: - self._stubs['delete_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProductSet', - request_serializer=product_search_service.DeleteProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_set'] - - @property - def create_product(self) -> Callable[ - [product_search_service.CreateProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the create product method over gRPC. - - Creates and returns a new product resource. - - Possible errors: - - - Returns INVALID_ARGUMENT if display_name is missing or longer - than 4096 characters. - - Returns INVALID_ARGUMENT if description is longer than 4096 - characters. - - Returns INVALID_ARGUMENT if product_category is missing or - invalid. - - Returns: - Callable[[~.CreateProductRequest], - Awaitable[~.Product]]: - 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_product' not in self._stubs: - self._stubs['create_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/CreateProduct', - request_serializer=product_search_service.CreateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['create_product'] - - @property - def list_products(self) -> Callable[ - [product_search_service.ListProductsRequest], - Awaitable[product_search_service.ListProductsResponse]]: - r"""Return a callable for the list products method over gRPC. - - Lists products in an unspecified order. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsRequest], - Awaitable[~.ListProductsResponse]]: - 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_products' not in self._stubs: - self._stubs['list_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListProducts', - request_serializer=product_search_service.ListProductsRequest.serialize, - response_deserializer=product_search_service.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - @property - def get_product(self) -> Callable[ - [product_search_service.GetProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the get product method over gRPC. - - Gets information associated with a Product. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns: - Callable[[~.GetProductRequest], - Awaitable[~.Product]]: - 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 'get_product' not in self._stubs: - self._stubs['get_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/GetProduct', - request_serializer=product_search_service.GetProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def update_product(self) -> Callable[ - [product_search_service.UpdateProductRequest], - Awaitable[product_search_service.Product]]: - r"""Return a callable for the update product method over gRPC. - - Makes changes to a Product resource. Only the ``display_name``, - ``description``, and ``labels`` fields can be updated right now. - - If labels are updated, the change will not be reflected in - queries until the next index time. - - Possible errors: - - - Returns NOT_FOUND if the Product does not exist. - - Returns INVALID_ARGUMENT if display_name is present in - update_mask but is missing from the request or longer than - 4096 characters. - - Returns INVALID_ARGUMENT if description is present in - update_mask but is longer than 4096 characters. - - Returns INVALID_ARGUMENT if product_category is present in - update_mask. - - Returns: - Callable[[~.UpdateProductRequest], - Awaitable[~.Product]]: - 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 'update_product' not in self._stubs: - self._stubs['update_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/UpdateProduct', - request_serializer=product_search_service.UpdateProductRequest.serialize, - response_deserializer=product_search_service.Product.deserialize, - ) - return self._stubs['update_product'] - - @property - def delete_product(self) -> Callable[ - [product_search_service.DeleteProductRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product method over gRPC. - - Permanently deletes a product and its reference - images. - Metadata of the product and all its images will be - deleted right away, but search queries against - ProductSets containing the product may still work until - all related caches are refreshed. - - Returns: - Callable[[~.DeleteProductRequest], - Awaitable[~.Empty]]: - 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_product' not in self._stubs: - self._stubs['delete_product'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteProduct', - request_serializer=product_search_service.DeleteProductRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product'] - - @property - def create_reference_image(self) -> Callable[ - [product_search_service.CreateReferenceImageRequest], - Awaitable[product_search_service.ReferenceImage]]: - r"""Return a callable for the create reference image method over gRPC. - - Creates and returns a new ReferenceImage resource. - - The ``bounding_poly`` field is optional. If ``bounding_poly`` is - not specified, the system will try to detect regions of interest - in the image that are compatible with the product_category on - the parent product. If it is specified, detection is ALWAYS - skipped. The system converts polygons into non-rotated - rectangles. - - Note that the pipeline will resize the image if the image - resolution is too large to process (above 50MP). - - Possible errors: - - - Returns INVALID_ARGUMENT if the image_uri is missing or - longer than 4096 characters. - - Returns INVALID_ARGUMENT if the product does not exist. - - Returns INVALID_ARGUMENT if bounding_poly is not provided, - and nothing compatible with the parent product's - product_category is detected. - - Returns INVALID_ARGUMENT if bounding_poly contains more than - 10 polygons. - - Returns: - Callable[[~.CreateReferenceImageRequest], - Awaitable[~.ReferenceImage]]: - 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_reference_image' not in self._stubs: - self._stubs['create_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/CreateReferenceImage', - request_serializer=product_search_service.CreateReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['create_reference_image'] - - @property - def delete_reference_image(self) -> Callable[ - [product_search_service.DeleteReferenceImageRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete reference image method over gRPC. - - Permanently deletes a reference image. - The image metadata will be deleted right away, but - search queries against ProductSets containing the image - may still work until all related caches are refreshed. - - The actual image files are not deleted from Google Cloud - Storage. - - Returns: - Callable[[~.DeleteReferenceImageRequest], - Awaitable[~.Empty]]: - 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_reference_image' not in self._stubs: - self._stubs['delete_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/DeleteReferenceImage', - request_serializer=product_search_service.DeleteReferenceImageRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_reference_image'] - - @property - def list_reference_images(self) -> Callable[ - [product_search_service.ListReferenceImagesRequest], - Awaitable[product_search_service.ListReferenceImagesResponse]]: - r"""Return a callable for the list reference images method over gRPC. - - Lists reference images. - - Possible errors: - - - Returns NOT_FOUND if the parent product does not exist. - - Returns INVALID_ARGUMENT if the page_size is greater than - 100, or less than 1. - - Returns: - Callable[[~.ListReferenceImagesRequest], - Awaitable[~.ListReferenceImagesResponse]]: - 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_reference_images' not in self._stubs: - self._stubs['list_reference_images'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListReferenceImages', - request_serializer=product_search_service.ListReferenceImagesRequest.serialize, - response_deserializer=product_search_service.ListReferenceImagesResponse.deserialize, - ) - return self._stubs['list_reference_images'] - - @property - def get_reference_image(self) -> Callable[ - [product_search_service.GetReferenceImageRequest], - Awaitable[product_search_service.ReferenceImage]]: - r"""Return a callable for the get reference image method over gRPC. - - Gets information associated with a ReferenceImage. - - Possible errors: - - - Returns NOT_FOUND if the specified image does not exist. - - Returns: - Callable[[~.GetReferenceImageRequest], - Awaitable[~.ReferenceImage]]: - 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 'get_reference_image' not in self._stubs: - self._stubs['get_reference_image'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/GetReferenceImage', - request_serializer=product_search_service.GetReferenceImageRequest.serialize, - response_deserializer=product_search_service.ReferenceImage.deserialize, - ) - return self._stubs['get_reference_image'] - - @property - def add_product_to_product_set(self) -> Callable[ - [product_search_service.AddProductToProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the add product to product set method over gRPC. - - Adds a Product to the specified ProductSet. If the Product is - already present, no change is made. - - One Product can be added to at most 100 ProductSets. - - Possible errors: - - - Returns NOT_FOUND if the Product or the ProductSet doesn't - exist. - - Returns: - Callable[[~.AddProductToProductSetRequest], - Awaitable[~.Empty]]: - 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 'add_product_to_product_set' not in self._stubs: - self._stubs['add_product_to_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/AddProductToProductSet', - request_serializer=product_search_service.AddProductToProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['add_product_to_product_set'] - - @property - def remove_product_from_product_set(self) -> Callable[ - [product_search_service.RemoveProductFromProductSetRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the remove product from product - set method over gRPC. - - Removes a Product from the specified ProductSet. - - Returns: - Callable[[~.RemoveProductFromProductSetRequest], - Awaitable[~.Empty]]: - 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 'remove_product_from_product_set' not in self._stubs: - self._stubs['remove_product_from_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/RemoveProductFromProductSet', - request_serializer=product_search_service.RemoveProductFromProductSetRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['remove_product_from_product_set'] - - @property - def list_products_in_product_set(self) -> Callable[ - [product_search_service.ListProductsInProductSetRequest], - Awaitable[product_search_service.ListProductsInProductSetResponse]]: - r"""Return a callable for the list products in product set method over gRPC. - - Lists the Products in a ProductSet, in an unspecified order. If - the ProductSet does not exist, the products field of the - response will be empty. - - Possible errors: - - - Returns INVALID_ARGUMENT if page_size is greater than 100 or - less than 1. - - Returns: - Callable[[~.ListProductsInProductSetRequest], - Awaitable[~.ListProductsInProductSetResponse]]: - 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_products_in_product_set' not in self._stubs: - self._stubs['list_products_in_product_set'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ListProductsInProductSet', - request_serializer=product_search_service.ListProductsInProductSetRequest.serialize, - response_deserializer=product_search_service.ListProductsInProductSetResponse.deserialize, - ) - return self._stubs['list_products_in_product_set'] - - @property - def import_product_sets(self) -> Callable[ - [product_search_service.ImportProductSetsRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the import product sets method over gRPC. - - Asynchronous API that imports a list of reference images to - specified product sets based on a list of image information. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) ``Operation.response`` - contains ``ImportProductSetsResponse``. (results) - - The input source of this method is a csv file on Google Cloud - Storage. For the format of the csv file please see - [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1p4beta1.ImportProductSetsGcsSource.csv_file_uri]. - - Returns: - Callable[[~.ImportProductSetsRequest], - 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 'import_product_sets' not in self._stubs: - self._stubs['import_product_sets'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/ImportProductSets', - request_serializer=product_search_service.ImportProductSetsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['import_product_sets'] - - @property - def purge_products(self) -> Callable[ - [product_search_service.PurgeProductsRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the purge products method over gRPC. - - Asynchronous API to delete all Products in a ProductSet or all - Products that are in no ProductSet. - - If a Product is a member of the specified ProductSet in addition - to other ProductSets, the Product will still be deleted. - - It is recommended to not delete the specified ProductSet until - after this operation has completed. It is also recommended to - not add any of the Products involved in the batch delete to a - new ProductSet while this operation is running because those - Products may still end up deleted. - - It's not possible to undo the PurgeProducts operation. - Therefore, it is recommended to keep the csv files used in - ImportProductSets (if that was how you originally built the - Product Set) before starting PurgeProducts, in case you need to - re-import the data after deletion. - - If the plan is to purge all of the Products from a ProductSet - and then re-use the empty ProductSet to re-import new Products - into the empty ProductSet, you must wait until the PurgeProducts - operation has finished for that ProductSet. - - The [google.longrunning.Operation][google.longrunning.Operation] - API can be used to keep track of the progress and results of the - request. ``Operation.metadata`` contains - ``BatchOperationMetadata``. (progress) - - Returns: - Callable[[~.PurgeProductsRequest], - 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 'purge_products' not in self._stubs: - self._stubs['purge_products'] = self.grpc_channel.unary_unary( - '/google.cloud.vision.v1p4beta1.ProductSearch/PurgeProducts', - request_serializer=product_search_service.PurgeProductsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['purge_products'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'ProductSearchGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py deleted file mode 100644 index 01807949..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/__init__.py +++ /dev/null @@ -1,206 +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 .face import ( - Celebrity, - FaceRecognitionParams, - FaceRecognitionResult, -) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Position, - Vertex, -) -from .image_annotator import ( - AnnotateFileRequest, - AnnotateFileResponse, - AnnotateImageRequest, - AnnotateImageResponse, - AsyncAnnotateFileRequest, - AsyncAnnotateFileResponse, - AsyncBatchAnnotateFilesRequest, - AsyncBatchAnnotateFilesResponse, - AsyncBatchAnnotateImagesRequest, - AsyncBatchAnnotateImagesResponse, - BatchAnnotateFilesRequest, - BatchAnnotateFilesResponse, - BatchAnnotateImagesRequest, - BatchAnnotateImagesResponse, - ColorInfo, - CropHint, - CropHintsAnnotation, - CropHintsParams, - DominantColorsAnnotation, - EntityAnnotation, - FaceAnnotation, - Feature, - GcsDestination, - GcsSource, - Image, - ImageAnnotationContext, - ImageContext, - ImageProperties, - ImageSource, - InputConfig, - LatLongRect, - LocalizedObjectAnnotation, - LocationInfo, - OperationMetadata, - OutputConfig, - Property, - SafeSearchAnnotation, - TextDetectionParams, - WebDetectionParams, - Likelihood, -) -from .product_search import ( - ProductSearchParams, - ProductSearchResults, -) -from .product_search_service import ( - AddProductToProductSetRequest, - BatchOperationMetadata, - CreateProductRequest, - CreateProductSetRequest, - CreateReferenceImageRequest, - DeleteProductRequest, - DeleteProductSetRequest, - DeleteReferenceImageRequest, - GetProductRequest, - GetProductSetRequest, - GetReferenceImageRequest, - ImportProductSetsGcsSource, - ImportProductSetsInputConfig, - ImportProductSetsRequest, - ImportProductSetsResponse, - ListProductSetsRequest, - ListProductSetsResponse, - ListProductsInProductSetRequest, - ListProductsInProductSetResponse, - ListProductsRequest, - ListProductsResponse, - ListReferenceImagesRequest, - ListReferenceImagesResponse, - Product, - ProductSet, - ProductSetPurgeConfig, - PurgeProductsRequest, - ReferenceImage, - RemoveProductFromProductSetRequest, - UpdateProductRequest, - UpdateProductSetRequest, -) -from .text_annotation import ( - Block, - Page, - Paragraph, - Symbol, - TextAnnotation, - Word, -) -from .web_detection import ( - WebDetection, -) - -__all__ = ( - 'Celebrity', - 'FaceRecognitionParams', - 'FaceRecognitionResult', - 'BoundingPoly', - 'NormalizedVertex', - 'Position', - 'Vertex', - 'AnnotateFileRequest', - 'AnnotateFileResponse', - 'AnnotateImageRequest', - 'AnnotateImageResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'AsyncBatchAnnotateImagesRequest', - 'AsyncBatchAnnotateImagesResponse', - 'BatchAnnotateFilesRequest', - 'BatchAnnotateFilesResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'ColorInfo', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'DominantColorsAnnotation', - 'EntityAnnotation', - 'FaceAnnotation', - 'Feature', - 'GcsDestination', - 'GcsSource', - 'Image', - 'ImageAnnotationContext', - 'ImageContext', - 'ImageProperties', - 'ImageSource', - 'InputConfig', - 'LatLongRect', - 'LocalizedObjectAnnotation', - 'LocationInfo', - 'OperationMetadata', - 'OutputConfig', - 'Property', - 'SafeSearchAnnotation', - 'TextDetectionParams', - 'WebDetectionParams', - 'Likelihood', - 'ProductSearchParams', - 'ProductSearchResults', - 'AddProductToProductSetRequest', - 'BatchOperationMetadata', - 'CreateProductRequest', - 'CreateProductSetRequest', - 'CreateReferenceImageRequest', - 'DeleteProductRequest', - 'DeleteProductSetRequest', - 'DeleteReferenceImageRequest', - 'GetProductRequest', - 'GetProductSetRequest', - 'GetReferenceImageRequest', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ListProductsRequest', - 'ListProductsResponse', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'Product', - 'ProductSet', - 'ProductSetPurgeConfig', - 'PurgeProductsRequest', - 'ReferenceImage', - 'RemoveProductFromProductSetRequest', - 'UpdateProductRequest', - 'UpdateProductSetRequest', - 'Block', - 'Page', - 'Paragraph', - 'Symbol', - 'TextAnnotation', - 'Word', - 'WebDetection', -) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py deleted file mode 100644 index 5bf133ea..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/face.py +++ /dev/null @@ -1,97 +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.vision.v1p4beta1', - manifest={ - 'FaceRecognitionParams', - 'Celebrity', - 'FaceRecognitionResult', - }, -) - - -class FaceRecognitionParams(proto.Message): - r"""Parameters for a celebrity recognition request. - - Attributes: - celebrity_set (Sequence[str]): - The resource names for one or more - [CelebritySet][google.cloud.vision.v1p4beta1.CelebritySet]s. - A celebrity set is preloaded and can be specified as - "builtin/default". If this is specified, the algorithm will - try to match the faces detected in the input image to the - Celebrities in the CelebritySets. - """ - - celebrity_set = proto.RepeatedField( - proto.STRING, - number=1, - ) - - -class Celebrity(proto.Message): - r"""A Celebrity is a group of Faces with an identity. - - Attributes: - name (str): - The resource name of the preloaded Celebrity. Has the format - ``builtin/{mid}``. - display_name (str): - The Celebrity's display name. - description (str): - The Celebrity's description. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - - -class FaceRecognitionResult(proto.Message): - r"""Information about a face's identity. - - Attributes: - celebrity (google.cloud.vision_v1p4beta1.types.Celebrity): - The [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] - that this face was matched to. - confidence (float): - Recognition confidence. Range [0, 1]. - """ - - celebrity = proto.Field( - proto.MESSAGE, - number=1, - message='Celebrity', - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py deleted file mode 100644 index fc03a711..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/geometry.py +++ /dev/null @@ -1,125 +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.vision.v1p4beta1', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - 'Position', - }, -) - - -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.vision_v1p4beta1.types.Vertex]): - The bounding polygon vertices. - normalized_vertices (Sequence[google.cloud.vision_v1p4beta1.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', - ) - - -class Position(proto.Message): - r"""A 3D position in the image, used primarily for Face detection - landmarks. A valid Position must have both x and y coordinates. - The position coordinates are in the same scale as the original - image. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate. - z (float): - Z coordinate (or depth). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - z = proto.Field( - proto.FLOAT, - number=3, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py deleted file mode 100644 index b0a73495..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/image_annotator.py +++ /dev/null @@ -1,1518 +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.vision_v1p4beta1.types import face -from google.cloud.vision_v1p4beta1.types import geometry -from google.cloud.vision_v1p4beta1.types import product_search -from google.cloud.vision_v1p4beta1.types import text_annotation -from google.cloud.vision_v1p4beta1.types import web_detection as gcv_web_detection -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 latlng_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p4beta1', - manifest={ - 'Likelihood', - 'Feature', - 'ImageSource', - 'Image', - 'FaceAnnotation', - 'LocationInfo', - 'Property', - 'EntityAnnotation', - 'LocalizedObjectAnnotation', - 'SafeSearchAnnotation', - 'LatLongRect', - 'ColorInfo', - 'DominantColorsAnnotation', - 'ImageProperties', - 'CropHint', - 'CropHintsAnnotation', - 'CropHintsParams', - 'WebDetectionParams', - 'TextDetectionParams', - 'ImageContext', - 'AnnotateImageRequest', - 'ImageAnnotationContext', - 'AnnotateImageResponse', - 'BatchAnnotateImagesRequest', - 'BatchAnnotateImagesResponse', - 'AnnotateFileRequest', - 'AnnotateFileResponse', - 'BatchAnnotateFilesRequest', - 'BatchAnnotateFilesResponse', - 'AsyncAnnotateFileRequest', - 'AsyncAnnotateFileResponse', - 'AsyncBatchAnnotateImagesRequest', - 'AsyncBatchAnnotateImagesResponse', - 'AsyncBatchAnnotateFilesRequest', - 'AsyncBatchAnnotateFilesResponse', - 'InputConfig', - 'OutputConfig', - 'GcsSource', - 'GcsDestination', - 'OperationMetadata', - }, -) - - -class Likelihood(proto.Enum): - r"""A bucketized representation of likelihood, which is intended - to give clients highly stable results across model upgrades. - """ - UNKNOWN = 0 - VERY_UNLIKELY = 1 - UNLIKELY = 2 - POSSIBLE = 3 - LIKELY = 4 - VERY_LIKELY = 5 - - -class Feature(proto.Message): - r"""The type of Google Cloud Vision API detection to perform, and the - maximum number of results to return for that type. Multiple - ``Feature`` objects can be specified in the ``features`` list. - - Attributes: - type_ (google.cloud.vision_v1p4beta1.types.Feature.Type): - The feature type. - max_results (int): - Maximum number of results of this type. Does not apply to - ``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or - ``CROP_HINTS``. - model (str): - Model to use for the feature. - Supported values: "builtin/stable" (the default - if unset) and "builtin/latest". - """ - class Type(proto.Enum): - r"""Type of Google Cloud Vision API feature to be extracted.""" - TYPE_UNSPECIFIED = 0 - FACE_DETECTION = 1 - LANDMARK_DETECTION = 2 - LOGO_DETECTION = 3 - LABEL_DETECTION = 4 - TEXT_DETECTION = 5 - DOCUMENT_TEXT_DETECTION = 11 - SAFE_SEARCH_DETECTION = 6 - IMAGE_PROPERTIES = 7 - CROP_HINTS = 9 - WEB_DETECTION = 10 - PRODUCT_SEARCH = 12 - OBJECT_LOCALIZATION = 19 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum=Type, - ) - max_results = proto.Field( - proto.INT32, - number=2, - ) - model = proto.Field( - proto.STRING, - number=3, - ) - - -class ImageSource(proto.Message): - r"""External image source (Google Cloud Storage or web URL image - location). - - Attributes: - gcs_image_uri (str): - **Use ``image_uri`` instead.** - - The 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. - image_uri (str): - The URI of the source image. Can be either: - - 1. A 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. - - 2. A publicly-accessible image HTTP/HTTPS URL. When fetching - images from HTTP/HTTPS URLs, Google cannot guarantee that - the request will be completed. Your request may fail if - the specified host denies the request (e.g. due to - request throttling or DOS prevention), or if Google - throttles requests to the site for abuse prevention. You - should not depend on externally-hosted images for - production applications. - - When both ``gcs_image_uri`` and ``image_uri`` are specified, - ``image_uri`` takes precedence. - """ - - gcs_image_uri = proto.Field( - proto.STRING, - number=1, - ) - image_uri = proto.Field( - proto.STRING, - number=2, - ) - - -class Image(proto.Message): - r"""Client image to perform Google Cloud Vision API tasks over. - - Attributes: - content (bytes): - Image content, represented as a stream of bytes. Note: As - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - source (google.cloud.vision_v1p4beta1.types.ImageSource): - Google Cloud Storage image location, or publicly-accessible - image URL. If both ``content`` and ``source`` are provided - for an image, ``content`` takes precedence and is used to - perform the image annotation request. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - source = proto.Field( - proto.MESSAGE, - number=2, - message='ImageSource', - ) - - -class FaceAnnotation(proto.Message): - r"""A face annotation object contains the results of face - detection. - - Attributes: - bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding polygon around the face. The coordinates of the - bounding box are in the original image's scale. The bounding - box is computed to "frame" the face in accordance with human - expectations. It is based on the landmarker results. Note - that one or more x and/or y coordinates may not be generated - in the ``BoundingPoly`` (the polygon will be unbounded) if - only a partial face appears in the image to be annotated. - fd_bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The ``fd_bounding_poly`` bounding polygon is tighter than - the ``boundingPoly``, and encloses only the skin part of the - face. Typically, it is used to eliminate the face from any - image analysis that detects the "amount of skin" visible in - an image. It is not based on the landmarker results, only on - the initial face detection, hence the fd (face detection) - prefix. - landmarks (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark]): - Detected face landmarks. - roll_angle (float): - Roll angle, which indicates the amount of - clockwise/anti-clockwise rotation of the face relative to - the image vertical about the axis perpendicular to the face. - Range [-180,180]. - pan_angle (float): - Yaw angle, which indicates the leftward/rightward angle that - the face is pointing relative to the vertical plane - perpendicular to the image. Range [-180,180]. - tilt_angle (float): - Pitch angle, which indicates the upwards/downwards angle - that the face is pointing relative to the image's horizontal - plane. Range [-180,180]. - detection_confidence (float): - Detection confidence. Range [0, 1]. - landmarking_confidence (float): - Face landmarking confidence. Range [0, 1]. - joy_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Joy likelihood. - sorrow_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Sorrow likelihood. - anger_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Anger likelihood. - surprise_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Surprise likelihood. - under_exposed_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Under-exposed likelihood. - blurred_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Blurred likelihood. - headwear_likelihood (google.cloud.vision_v1p4beta1.types.Likelihood): - Headwear likelihood. - recognition_result (Sequence[google.cloud.vision_v1p4beta1.types.FaceRecognitionResult]): - Additional recognition information. Only computed if - image_context.face_recognition_params is provided, **and** a - match is found to a - [Celebrity][google.cloud.vision.v1p4beta1.Celebrity] in the - input - [CelebritySet][google.cloud.vision.v1p4beta1.CelebritySet]. - This field is sorted in order of decreasing confidence - values. - """ - - class Landmark(proto.Message): - r"""A face-specific landmark (for example, a face feature). - - Attributes: - type_ (google.cloud.vision_v1p4beta1.types.FaceAnnotation.Landmark.Type): - Face landmark type. - position (google.cloud.vision_v1p4beta1.types.Position): - Face landmark position. - """ - class Type(proto.Enum): - r"""Face landmark (feature) type. Left and right are defined from the - vantage of the viewer of the image without considering mirror - projections typical of photos. So, ``LEFT_EYE``, typically, is the - person's right eye. - """ - UNKNOWN_LANDMARK = 0 - LEFT_EYE = 1 - RIGHT_EYE = 2 - LEFT_OF_LEFT_EYEBROW = 3 - RIGHT_OF_LEFT_EYEBROW = 4 - LEFT_OF_RIGHT_EYEBROW = 5 - RIGHT_OF_RIGHT_EYEBROW = 6 - MIDPOINT_BETWEEN_EYES = 7 - NOSE_TIP = 8 - UPPER_LIP = 9 - LOWER_LIP = 10 - MOUTH_LEFT = 11 - MOUTH_RIGHT = 12 - MOUTH_CENTER = 13 - NOSE_BOTTOM_RIGHT = 14 - NOSE_BOTTOM_LEFT = 15 - NOSE_BOTTOM_CENTER = 16 - LEFT_EYE_TOP_BOUNDARY = 17 - LEFT_EYE_RIGHT_CORNER = 18 - LEFT_EYE_BOTTOM_BOUNDARY = 19 - LEFT_EYE_LEFT_CORNER = 20 - RIGHT_EYE_TOP_BOUNDARY = 21 - RIGHT_EYE_RIGHT_CORNER = 22 - RIGHT_EYE_BOTTOM_BOUNDARY = 23 - RIGHT_EYE_LEFT_CORNER = 24 - LEFT_EYEBROW_UPPER_MIDPOINT = 25 - RIGHT_EYEBROW_UPPER_MIDPOINT = 26 - LEFT_EAR_TRAGION = 27 - RIGHT_EAR_TRAGION = 28 - LEFT_EYE_PUPIL = 29 - RIGHT_EYE_PUPIL = 30 - FOREHEAD_GLABELLA = 31 - CHIN_GNATHION = 32 - CHIN_LEFT_GONION = 33 - CHIN_RIGHT_GONION = 34 - - type_ = proto.Field( - proto.ENUM, - number=3, - enum='FaceAnnotation.Landmark.Type', - ) - position = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.Position, - ) - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - fd_bounding_poly = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - landmarks = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=Landmark, - ) - roll_angle = proto.Field( - proto.FLOAT, - number=4, - ) - pan_angle = proto.Field( - proto.FLOAT, - number=5, - ) - tilt_angle = proto.Field( - proto.FLOAT, - number=6, - ) - detection_confidence = proto.Field( - proto.FLOAT, - number=7, - ) - landmarking_confidence = proto.Field( - proto.FLOAT, - number=8, - ) - joy_likelihood = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - sorrow_likelihood = proto.Field( - proto.ENUM, - number=10, - enum='Likelihood', - ) - anger_likelihood = proto.Field( - proto.ENUM, - number=11, - enum='Likelihood', - ) - surprise_likelihood = proto.Field( - proto.ENUM, - number=12, - enum='Likelihood', - ) - under_exposed_likelihood = proto.Field( - proto.ENUM, - number=13, - enum='Likelihood', - ) - blurred_likelihood = proto.Field( - proto.ENUM, - number=14, - enum='Likelihood', - ) - headwear_likelihood = proto.Field( - proto.ENUM, - number=15, - enum='Likelihood', - ) - recognition_result = proto.RepeatedField( - proto.MESSAGE, - number=16, - message=face.FaceRecognitionResult, - ) - - -class LocationInfo(proto.Message): - r"""Detected entity location information. - - Attributes: - lat_lng (google.type.latlng_pb2.LatLng): - lat/long location coordinates. - """ - - lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - - -class Property(proto.Message): - r"""A ``Property`` consists of a user-supplied name/value pair. - - Attributes: - name (str): - Name of the property. - value (str): - Value of the property. - uint64_value (int): - Value of numeric properties. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - uint64_value = proto.Field( - proto.UINT64, - number=3, - ) - - -class EntityAnnotation(proto.Message): - r"""Set of detected entity features. - - Attributes: - mid (str): - Opaque entity ID. Some IDs may be available in `Google - Knowledge Graph Search - API `__. - locale (str): - The language code for the locale in which the entity textual - ``description`` is expressed. - description (str): - Entity textual description, expressed in its ``locale`` - language. - score (float): - Overall score of the result. Range [0, 1]. - confidence (float): - **Deprecated. Use ``score`` instead.** The accuracy of the - entity detection in an image. For example, for an image in - which the "Eiffel Tower" entity is detected, this field - represents the confidence that there is a tower in the query - image. Range [0, 1]. - topicality (float): - The relevancy of the ICA (Image Content Annotation) label to - the image. For example, the relevancy of "tower" is likely - higher to an image containing the detected "Eiffel Tower" - than to an image containing a detected distant towering - building, even though the confidence that there is a tower - in each image may be the same. Range [0, 1]. - bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - Image region to which this entity belongs. Not produced for - ``LABEL_DETECTION`` features. - locations (Sequence[google.cloud.vision_v1p4beta1.types.LocationInfo]): - The location information for the detected entity. Multiple - ``LocationInfo`` elements can be present because one - location may indicate the location of the scene in the - image, and another location may indicate the location of the - place where the image was taken. Location information is - usually present for landmarks. - properties (Sequence[google.cloud.vision_v1p4beta1.types.Property]): - Some entities may have optional user-supplied ``Property`` - (name/value) fields, such a score or string that qualifies - the entity. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - locale = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - topicality = proto.Field( - proto.FLOAT, - number=6, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=7, - message=geometry.BoundingPoly, - ) - locations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='LocationInfo', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Property', - ) - - -class LocalizedObjectAnnotation(proto.Message): - r"""Set of detected objects with bounding boxes. - - Attributes: - mid (str): - Object ID that should align with - EntityAnnotation mid. - 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. - name (str): - Object name, expressed in its ``language_code`` language. - score (float): - Score of the result. Range [0, 1]. - bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - Image region to which this object belongs. - This must be populated. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - name = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=5, - message=geometry.BoundingPoly, - ) - - -class SafeSearchAnnotation(proto.Message): - r"""Set of features pertaining to the image, computed by computer - vision methods over safe-search verticals (for example, adult, - spoof, medical, violence). - - Attributes: - adult (google.cloud.vision_v1p4beta1.types.Likelihood): - Represents the adult content likelihood for - the image. Adult content may contain elements - such as nudity, pornographic images or cartoons, - or sexual activities. - spoof (google.cloud.vision_v1p4beta1.types.Likelihood): - Spoof likelihood. The likelihood that an - modification was made to the image's canonical - version to make it appear funny or offensive. - medical (google.cloud.vision_v1p4beta1.types.Likelihood): - Likelihood that this is a medical image. - violence (google.cloud.vision_v1p4beta1.types.Likelihood): - Likelihood that this image contains violent - content. - racy (google.cloud.vision_v1p4beta1.types.Likelihood): - Likelihood that the request image contains - racy content. Racy content may include (but is - not limited to) skimpy or sheer clothing, - strategically covered nudity, lewd or - provocative poses, or close-ups of sensitive - body areas. - """ - - adult = proto.Field( - proto.ENUM, - number=1, - enum='Likelihood', - ) - spoof = proto.Field( - proto.ENUM, - number=2, - enum='Likelihood', - ) - medical = proto.Field( - proto.ENUM, - number=3, - enum='Likelihood', - ) - violence = proto.Field( - proto.ENUM, - number=4, - enum='Likelihood', - ) - racy = proto.Field( - proto.ENUM, - number=9, - enum='Likelihood', - ) - - -class LatLongRect(proto.Message): - r"""Rectangle determined by min and max ``LatLng`` pairs. - - Attributes: - min_lat_lng (google.type.latlng_pb2.LatLng): - Min lat/long pair. - max_lat_lng (google.type.latlng_pb2.LatLng): - Max lat/long pair. - """ - - min_lat_lng = proto.Field( - proto.MESSAGE, - number=1, - message=latlng_pb2.LatLng, - ) - max_lat_lng = proto.Field( - proto.MESSAGE, - number=2, - message=latlng_pb2.LatLng, - ) - - -class ColorInfo(proto.Message): - r"""Color information consists of RGB channels, score, and the - fraction of the image that the color occupies in the image. - - Attributes: - color (google.type.color_pb2.Color): - RGB components of the color. - score (float): - Image-specific score for this color. Value in range [0, 1]. - pixel_fraction (float): - The fraction of pixels the color occupies in the image. - Value in range [0, 1]. - """ - - color = proto.Field( - proto.MESSAGE, - number=1, - message=color_pb2.Color, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - pixel_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class DominantColorsAnnotation(proto.Message): - r"""Set of dominant colors and their corresponding scores. - - Attributes: - colors (Sequence[google.cloud.vision_v1p4beta1.types.ColorInfo]): - RGB color values with their score and pixel - fraction. - """ - - colors = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ColorInfo', - ) - - -class ImageProperties(proto.Message): - r"""Stores image properties, such as dominant colors. - - Attributes: - dominant_colors (google.cloud.vision_v1p4beta1.types.DominantColorsAnnotation): - If present, dominant colors completed - successfully. - """ - - dominant_colors = proto.Field( - proto.MESSAGE, - number=1, - message='DominantColorsAnnotation', - ) - - -class CropHint(proto.Message): - r"""Single crop hint that is used to generate a new crop when - serving an image. - - Attributes: - bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding polygon for the crop region. The - coordinates of the bounding box are in the - original image's scale. - confidence (float): - Confidence of this being a salient region. Range [0, 1]. - importance_fraction (float): - Fraction of importance of this salient region - with respect to the original image. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - importance_fraction = proto.Field( - proto.FLOAT, - number=3, - ) - - -class CropHintsAnnotation(proto.Message): - r"""Set of crop hints that are used to generate new crops when - serving images. - - Attributes: - crop_hints (Sequence[google.cloud.vision_v1p4beta1.types.CropHint]): - Crop hint results. - """ - - crop_hints = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='CropHint', - ) - - -class CropHintsParams(proto.Message): - r"""Parameters for crop hints annotation request. - - Attributes: - aspect_ratios (Sequence[float]): - Aspect ratios in floats, representing the - ratio of the width to the height of the image. - For example, if the desired aspect ratio is 4/3, - the corresponding float value should be 1.33333. - If not specified, the best possible crop is - returned. The number of provided aspect ratios - is limited to a maximum of 16; any aspect ratios - provided after the 16th are ignored. - """ - - aspect_ratios = proto.RepeatedField( - proto.FLOAT, - number=1, - ) - - -class WebDetectionParams(proto.Message): - r"""Parameters for web detection request. - - Attributes: - include_geo_results (bool): - Whether to include results derived from the - geo information in the image. - """ - - include_geo_results = proto.Field( - proto.BOOL, - number=2, - ) - - -class TextDetectionParams(proto.Message): - r"""Parameters for text detections. This is used to control - TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features. - - Attributes: - enable_text_detection_confidence_score (bool): - By default, Cloud Vision API only includes confidence score - for DOCUMENT_TEXT_DETECTION result. Set the flag to true to - include confidence score for TEXT_DETECTION as well. - """ - - enable_text_detection_confidence_score = proto.Field( - proto.BOOL, - number=9, - ) - - -class ImageContext(proto.Message): - r"""Image context and/or feature-specific parameters. - - Attributes: - lat_long_rect (google.cloud.vision_v1p4beta1.types.LatLongRect): - Not used. - language_hints (Sequence[str]): - List of languages to use for TEXT_DETECTION. 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). - Text detection returns an error if one or more of the - specified languages is not one of the `supported - languages `__. - crop_hints_params (google.cloud.vision_v1p4beta1.types.CropHintsParams): - Parameters for crop hints annotation request. - face_recognition_params (google.cloud.vision_v1p4beta1.types.FaceRecognitionParams): - Parameters for face recognition. - product_search_params (google.cloud.vision_v1p4beta1.types.ProductSearchParams): - Parameters for product search. - web_detection_params (google.cloud.vision_v1p4beta1.types.WebDetectionParams): - Parameters for web detection. - text_detection_params (google.cloud.vision_v1p4beta1.types.TextDetectionParams): - Parameters for text detection and document - text detection. - """ - - lat_long_rect = proto.Field( - proto.MESSAGE, - number=1, - message='LatLongRect', - ) - language_hints = proto.RepeatedField( - proto.STRING, - number=2, - ) - crop_hints_params = proto.Field( - proto.MESSAGE, - number=4, - message='CropHintsParams', - ) - face_recognition_params = proto.Field( - proto.MESSAGE, - number=10, - message=face.FaceRecognitionParams, - ) - product_search_params = proto.Field( - proto.MESSAGE, - number=5, - message=product_search.ProductSearchParams, - ) - web_detection_params = proto.Field( - proto.MESSAGE, - number=6, - message='WebDetectionParams', - ) - text_detection_params = proto.Field( - proto.MESSAGE, - number=12, - message='TextDetectionParams', - ) - - -class AnnotateImageRequest(proto.Message): - r"""Request for performing Google Cloud Vision API tasks over a - user-provided image, with user-requested features, and with - context information. - - Attributes: - image (google.cloud.vision_v1p4beta1.types.Image): - The image to be processed. - features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): - Requested features. - image_context (google.cloud.vision_v1p4beta1.types.ImageContext): - Additional context that may accompany the - image. - """ - - image = proto.Field( - proto.MESSAGE, - number=1, - message='Image', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - - -class ImageAnnotationContext(proto.Message): - r"""If an image was produced from a file (e.g. a PDF), this - message gives information about the source of that image. - - Attributes: - uri (str): - The URI of the file used to produce the - image. - page_number (int): - If the file was a PDF or TIFF, this field - gives the page number within the file used to - produce the image. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - page_number = proto.Field( - proto.INT32, - number=2, - ) - - -class AnnotateImageResponse(proto.Message): - r"""Response to an image annotation request. - - Attributes: - face_annotations (Sequence[google.cloud.vision_v1p4beta1.types.FaceAnnotation]): - If present, face detection has completed - successfully. - landmark_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): - If present, landmark detection has completed - successfully. - logo_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): - If present, logo detection has completed - successfully. - label_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): - If present, label detection has completed - successfully. - localized_object_annotations (Sequence[google.cloud.vision_v1p4beta1.types.LocalizedObjectAnnotation]): - If present, localized object detection has - completed successfully. This will be sorted - descending by confidence score. - text_annotations (Sequence[google.cloud.vision_v1p4beta1.types.EntityAnnotation]): - If present, text (OCR) detection has - completed successfully. - full_text_annotation (google.cloud.vision_v1p4beta1.types.TextAnnotation): - If present, text (OCR) detection or document - (OCR) text detection has completed successfully. - This annotation provides the structural - hierarchy for the OCR detected text. - safe_search_annotation (google.cloud.vision_v1p4beta1.types.SafeSearchAnnotation): - If present, safe-search annotation has - completed successfully. - image_properties_annotation (google.cloud.vision_v1p4beta1.types.ImageProperties): - If present, image properties were extracted - successfully. - crop_hints_annotation (google.cloud.vision_v1p4beta1.types.CropHintsAnnotation): - If present, crop hints have completed - successfully. - web_detection (google.cloud.vision_v1p4beta1.types.WebDetection): - If present, web detection has completed - successfully. - product_search_results (google.cloud.vision_v1p4beta1.types.ProductSearchResults): - If present, product search has completed - successfully. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the operation. Note - that filled-in image annotations are guaranteed to be - correct, even when ``error`` is set. - context (google.cloud.vision_v1p4beta1.types.ImageAnnotationContext): - If present, contextual information is needed - to understand where this image comes from. - """ - - face_annotations = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='FaceAnnotation', - ) - landmark_annotations = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='EntityAnnotation', - ) - logo_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='EntityAnnotation', - ) - label_annotations = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='EntityAnnotation', - ) - localized_object_annotations = proto.RepeatedField( - proto.MESSAGE, - number=22, - message='LocalizedObjectAnnotation', - ) - text_annotations = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='EntityAnnotation', - ) - full_text_annotation = proto.Field( - proto.MESSAGE, - number=12, - message=text_annotation.TextAnnotation, - ) - safe_search_annotation = proto.Field( - proto.MESSAGE, - number=6, - message='SafeSearchAnnotation', - ) - image_properties_annotation = proto.Field( - proto.MESSAGE, - number=8, - message='ImageProperties', - ) - crop_hints_annotation = proto.Field( - proto.MESSAGE, - number=11, - message='CropHintsAnnotation', - ) - web_detection = proto.Field( - proto.MESSAGE, - number=13, - message=gcv_web_detection.WebDetection, - ) - product_search_results = proto.Field( - proto.MESSAGE, - number=14, - message=product_search.ProductSearchResults, - ) - error = proto.Field( - proto.MESSAGE, - number=9, - message=status_pb2.Status, - ) - context = proto.Field( - proto.MESSAGE, - number=21, - message='ImageAnnotationContext', - ) - - -class BatchAnnotateImagesRequest(proto.Message): - r"""Multiple image annotation requests are batched into a single - service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - - -class BatchAnnotateImagesResponse(proto.Message): - r"""Response to a batch image annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): - Individual responses to image annotation - requests within the batch. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageResponse', - ) - - -class AnnotateFileRequest(proto.Message): - r"""A request to annotate one single file, e.g. a PDF, TIFF or - GIF file. - - Attributes: - input_config (google.cloud.vision_v1p4beta1.types.InputConfig): - Required. Information about the input file. - features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): - Required. Requested features. - image_context (google.cloud.vision_v1p4beta1.types.ImageContext): - Additional context that may accompany the - image(s) in the file. - pages (Sequence[int]): - Pages of the file to perform image - annotation. - Pages starts from 1, we assume the first page of - the file is page 1. At most 5 pages are - supported per request. Pages can be negative. - Page 1 means the first page. - Page 2 means the second page. - Page -1 means the last page. - Page -2 means the second to the last page. - - If the file is GIF instead of PDF or TIFF, page - refers to GIF frames. - If this field is empty, by default the service - performs image annotation for the first 5 pages - of the file. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - pages = proto.RepeatedField( - proto.INT32, - number=4, - ) - - -class AnnotateFileResponse(proto.Message): - r"""Response to a single file annotation request. A file may - contain one or more images, which individually have their own - responses. - - Attributes: - input_config (google.cloud.vision_v1p4beta1.types.InputConfig): - Information about the file for which this - response is generated. - responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageResponse]): - Individual responses to images found within the file. This - field will be empty if the ``error`` field is set. - total_pages (int): - This field gives the total number of pages in - the file. - error (google.rpc.status_pb2.Status): - If set, represents the error message for the failed request. - The ``responses`` field will not be set in this case. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - responses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='AnnotateImageResponse', - ) - total_pages = proto.Field( - proto.INT32, - number=3, - ) - error = proto.Field( - proto.MESSAGE, - number=4, - message=status_pb2.Status, - ) - - -class BatchAnnotateFilesRequest(proto.Message): - r"""A list of requests to annotate files using the - BatchAnnotateFiles API. - - Attributes: - requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileRequest]): - Required. The list of file annotation - requests. Right now we support only one - AnnotateFileRequest in - BatchAnnotateFilesRequest. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateFileRequest', - ) - - -class BatchAnnotateFilesResponse(proto.Message): - r"""A list of file annotation responses. - - Attributes: - responses (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateFileResponse]): - The list of file annotation responses, each - response corresponding to each - AnnotateFileRequest in - BatchAnnotateFilesRequest. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateFileResponse', - ) - - -class AsyncAnnotateFileRequest(proto.Message): - r"""An offline file annotation request. - - Attributes: - input_config (google.cloud.vision_v1p4beta1.types.InputConfig): - Required. Information about the input file. - features (Sequence[google.cloud.vision_v1p4beta1.types.Feature]): - Required. Requested features. - image_context (google.cloud.vision_v1p4beta1.types.ImageContext): - Additional context that may accompany the - image(s) in the file. - output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): - Required. The desired output location and - metadata (e.g. format). - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - features = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Feature', - ) - image_context = proto.Field( - proto.MESSAGE, - number=3, - message='ImageContext', - ) - output_config = proto.Field( - proto.MESSAGE, - number=4, - message='OutputConfig', - ) - - -class AsyncAnnotateFileResponse(proto.Message): - r"""The response for a single offline file annotation request. - - Attributes: - output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): - The output location and metadata from - AsyncAnnotateFileRequest. - """ - - output_config = proto.Field( - proto.MESSAGE, - number=1, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateImagesRequest(proto.Message): - r"""Request for async image annotation for a list of images. - - Attributes: - requests (Sequence[google.cloud.vision_v1p4beta1.types.AnnotateImageRequest]): - Required. Individual image annotation - requests for this batch. - output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): - Required. The desired output location and - metadata (e.g. format). - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AnnotateImageRequest', - ) - output_config = proto.Field( - proto.MESSAGE, - number=2, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateImagesResponse(proto.Message): - r"""Response to an async batch image annotation request. - - Attributes: - output_config (google.cloud.vision_v1p4beta1.types.OutputConfig): - The output location and metadata from - AsyncBatchAnnotateImagesRequest. - """ - - output_config = proto.Field( - proto.MESSAGE, - number=1, - message='OutputConfig', - ) - - -class AsyncBatchAnnotateFilesRequest(proto.Message): - r"""Multiple async file annotation requests are batched into a - single service call. - - Attributes: - requests (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileRequest]): - Required. Individual async file annotation - requests for this batch. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileRequest', - ) - - -class AsyncBatchAnnotateFilesResponse(proto.Message): - r"""Response to an async batch file annotation request. - - Attributes: - responses (Sequence[google.cloud.vision_v1p4beta1.types.AsyncAnnotateFileResponse]): - The list of file annotation responses, one - for each request in - AsyncBatchAnnotateFilesRequest. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='AsyncAnnotateFileResponse', - ) - - -class InputConfig(proto.Message): - r"""The desired input location and metadata. - - Attributes: - gcs_source (google.cloud.vision_v1p4beta1.types.GcsSource): - The Google Cloud Storage location to read the - input from. - content (bytes): - File content, represented as a stream of bytes. Note: As - with all ``bytes`` fields, protobuffers use a pure binary - representation, whereas JSON representations use base64. - - Currently, this field only works for BatchAnnotateFiles - requests. It does not work for AsyncBatchAnnotateFiles - requests. - mime_type (str): - The type of the file. Currently only - "application/pdf", "image/tiff" and "image/gif" - are supported. Wildcards are not supported. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - message='GcsSource', - ) - content = proto.Field( - proto.BYTES, - number=3, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class OutputConfig(proto.Message): - r"""The desired output location and metadata. - - Attributes: - gcs_destination (google.cloud.vision_v1p4beta1.types.GcsDestination): - The Google Cloud Storage location to write - the output(s) to. - batch_size (int): - The max number of response protos to put into each output - JSON file 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 response - protos will be generated. If ``batch_size`` = 20, then 5 - json files each containing 20 response protos will be - written under the prefix ``gcs_destination``.\ ``uri``. - - Currently, batch_size only applies to GcsDestination, with - potential future support for other output configurations. - """ - - gcs_destination = proto.Field( - proto.MESSAGE, - number=1, - message='GcsDestination', - ) - batch_size = proto.Field( - proto.INT32, - number=2, - ) - - -class GcsSource(proto.Message): - r"""The Google Cloud Storage location where the input will be - read from. - - Attributes: - uri (str): - Google Cloud Storage URI for the input file. - This must only be a Google Cloud Storage object. - Wildcards are not currently supported. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class GcsDestination(proto.Message): - r"""The Google Cloud Storage location where the output will be - written to. - - Attributes: - uri (str): - Google Cloud Storage URI prefix where the results will be - stored. Results will be in JSON format and preceded by its - corresponding input URI prefix. This field can either - represent a gcs file prefix or gcs directory. In either - case, the uri should be unique because in order to get all - of the output files, you will need to do a wildcard gcs - search on the uri prefix you provide. - - Examples: - - - File Prefix: gs://bucket-name/here/filenameprefix The - output files will be created in gs://bucket-name/here/ - and the names of the output files will begin with - "filenameprefix". - - - Directory Prefix: gs://bucket-name/some/location/ The - output files will be created in - gs://bucket-name/some/location/ and the names of the - output files could be anything because there was no - filename prefix specified. - - If multiple outputs, each response is still - AnnotateFileResponse, each of which contains some subset of - the full list of AnnotateImageResponse. Multiple outputs can - happen if, for example, the output JSON is too large and - overflows into multiple sharded files. - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class OperationMetadata(proto.Message): - r"""Contains metadata for the BatchAnnotateImages operation. - - Attributes: - state (google.cloud.vision_v1p4beta1.types.OperationMetadata.State): - Current state of the batch operation. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was received. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the operation result was last - updated. - """ - class State(proto.Enum): - r"""Batch operation states.""" - STATE_UNSPECIFIED = 0 - CREATED = 1 - RUNNING = 2 - DONE = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - create_time = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=6, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py deleted file mode 100644 index f6290f4a..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search.py +++ /dev/null @@ -1,222 +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.vision_v1p4beta1.types import geometry -from google.cloud.vision_v1p4beta1.types import product_search_service -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p4beta1', - manifest={ - 'ProductSearchParams', - 'ProductSearchResults', - }, -) - - -class ProductSearchParams(proto.Message): - r"""Parameters for a product search request. - - Attributes: - bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding polygon around the area of - interest in the image. If it is not specified, - system discretion will be applied. - product_set (str): - The resource name of a - [ProductSet][google.cloud.vision.v1p4beta1.ProductSet] to be - searched for similar images. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. - product_categories (Sequence[str]): - The list of product categories to search in. - Currently, we only consider the first category, - and either "homegoods-v2", "apparel-v2", - "toys-v2", "packagedgoods-v1", or "general-v1" - should be specified. The legacy categories - "homegoods", "apparel", and "toys" are still - supported but will be deprecated. For new - products, please use "homegoods-v2", - "apparel-v2", or "toys-v2" for better product - search accuracy. It is recommended to migrate - existing products to these categories as well. - filter (str): - The filtering expression. This can be used to - restrict search results based on Product labels. - We currently support an AND of OR of key-value - expressions, where each expression within an OR - must have the same key. An '=' should be used to - connect the key and value. - For example, "(color = red OR color = blue) AND - brand = Google" is acceptable, but "(color = red - OR brand = Google)" is not acceptable. "color: - red" is not acceptable because it uses a ':' - instead of an '='. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=9, - message=geometry.BoundingPoly, - ) - product_set = proto.Field( - proto.STRING, - number=6, - ) - product_categories = proto.RepeatedField( - proto.STRING, - number=7, - ) - filter = proto.Field( - proto.STRING, - number=8, - ) - - -class ProductSearchResults(proto.Message): - r"""Results for a product search request. - - Attributes: - index_time (google.protobuf.timestamp_pb2.Timestamp): - Timestamp of the index which provided these - results. Products added to the product set and - products removed from the product set after this - time are not reflected in the current results. - results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.Result]): - List of results, one for each product match. - product_grouped_results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.GroupedResult]): - List of results grouped by products detected - in the query image. Each entry corresponds to - one bounding polygon in the query image, and - contains the matching products specific to that - region. There may be duplicate product matches - in the union of all the per-product results. - """ - - class Result(proto.Message): - r"""Information about a product. - - Attributes: - product (google.cloud.vision_v1p4beta1.types.Product): - The Product. - score (float): - A confidence level on the match, ranging from - 0 (no confidence) to 1 (full confidence). - image (str): - The resource name of the image from the - product that is the closest match to the query. - """ - - product = proto.Field( - proto.MESSAGE, - number=1, - message=product_search_service.Product, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - image = proto.Field( - proto.STRING, - number=3, - ) - - class ObjectAnnotation(proto.Message): - r"""Prediction for what the object in the bounding box is. - - Attributes: - mid (str): - Object ID that should align with - EntityAnnotation mid. - 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. - name (str): - Object name, expressed in its ``language_code`` language. - score (float): - Score of the result. Range [0, 1]. - """ - - mid = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - name = proto.Field( - proto.STRING, - number=3, - ) - score = proto.Field( - proto.FLOAT, - number=4, - ) - - class GroupedResult(proto.Message): - r"""Information about the products similar to a single product in - a query image. - - Attributes: - bounding_poly (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding polygon around the product - detected in the query image. - results (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.Result]): - List of results, one for each product match. - object_annotations (Sequence[google.cloud.vision_v1p4beta1.types.ProductSearchResults.ObjectAnnotation]): - List of generic predictions for the object in - the bounding box. - """ - - bounding_poly = proto.Field( - proto.MESSAGE, - number=1, - message=geometry.BoundingPoly, - ) - results = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='ProductSearchResults.Result', - ) - object_annotations = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='ProductSearchResults.ObjectAnnotation', - ) - - index_time = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - results = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=Result, - ) - product_grouped_results = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=GroupedResult, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py deleted file mode 100644 index 1ca5c357..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/product_search_service.py +++ /dev/null @@ -1,1077 +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.vision_v1p4beta1.types import geometry -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p4beta1', - manifest={ - 'Product', - 'ProductSet', - 'ReferenceImage', - 'CreateProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'GetProductRequest', - 'UpdateProductRequest', - 'DeleteProductRequest', - 'CreateProductSetRequest', - 'ListProductSetsRequest', - 'ListProductSetsResponse', - 'GetProductSetRequest', - 'UpdateProductSetRequest', - 'DeleteProductSetRequest', - 'CreateReferenceImageRequest', - 'ListReferenceImagesRequest', - 'ListReferenceImagesResponse', - 'GetReferenceImageRequest', - 'DeleteReferenceImageRequest', - 'AddProductToProductSetRequest', - 'RemoveProductFromProductSetRequest', - 'ListProductsInProductSetRequest', - 'ListProductsInProductSetResponse', - 'ImportProductSetsGcsSource', - 'ImportProductSetsInputConfig', - 'ImportProductSetsRequest', - 'ImportProductSetsResponse', - 'BatchOperationMetadata', - 'ProductSetPurgeConfig', - 'PurgeProductsRequest', - }, -) - - -class Product(proto.Message): - r"""A Product contains ReferenceImages. - - Attributes: - name (str): - The resource name of the product. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - - This field is ignored when creating a product. - display_name (str): - The user-provided name for this Product. Must - not be empty. Must be at most 4096 characters - long. - description (str): - User-provided metadata to be stored with this - product. Must be at most 4096 characters long. - product_category (str): - Immutable. The category for the product - identified by the reference image. This should - be either "homegoods-v2", "apparel-v2", or - "toys-v2". The legacy categories "homegoods", - "apparel", and "toys" are still supported, but - these should not be used for new products. - product_labels (Sequence[google.cloud.vision_v1p4beta1.types.Product.KeyValue]): - Key-value pairs that can be attached to a product. At query - time, constraints can be specified based on the - product_labels. - - Note that integer values can be provided as strings, e.g. - "1199". Only strings with integer values can match a - range-based restriction which is to be supported soon. - - Multiple values can be assigned to the same key. One product - may have up to 500 product_labels. - - Notice that the total number of distinct product_labels over - all products in one ProductSet cannot exceed 1M, otherwise - the product search pipeline will refuse to work for that - ProductSet. - """ - - class KeyValue(proto.Message): - r"""A product label represented as a key-value pair. - - Attributes: - key (str): - The key of the label attached to the product. - Cannot be empty and cannot exceed 128 bytes. - value (str): - The value of the label attached to the - product. Cannot be empty and cannot exceed 128 - bytes. - """ - - key = proto.Field( - proto.STRING, - number=1, - ) - value = proto.Field( - proto.STRING, - number=2, - ) - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - product_category = proto.Field( - proto.STRING, - number=4, - ) - product_labels = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=KeyValue, - ) - - -class ProductSet(proto.Message): - r"""A ProductSet contains Products. A ProductSet can contain a - maximum of 1 million reference images. If the limit is exceeded, - periodic indexing will fail. - - Attributes: - name (str): - The resource name of the ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID``. - - This field is ignored when creating a ProductSet. - display_name (str): - The user-provided name for this ProductSet. - Must not be empty. Must be at most 4096 - characters long. - index_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which this - ProductSet was last indexed. Query results will - reflect all updates before this time. If this - ProductSet has never been indexed, this - timestamp is the default value - "1970-01-01T00:00:00Z". - - This field is ignored when creating a - ProductSet. - index_error (google.rpc.status_pb2.Status): - Output only. If there was an error with - indexing the product set, the field is - populated. - This field is ignored when creating a - ProductSet. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - display_name = proto.Field( - proto.STRING, - number=2, - ) - index_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - index_error = proto.Field( - proto.MESSAGE, - number=4, - message=status_pb2.Status, - ) - - -class ReferenceImage(proto.Message): - r"""A ``ReferenceImage`` represents a product image and its associated - metadata, such as bounding boxes. - - Attributes: - name (str): - The resource name of the reference image. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - - This field is ignored when creating a reference image. - uri (str): - Required. The Google Cloud Storage URI of the reference - image. - - The URI must start with ``gs://``. - bounding_polys (Sequence[google.cloud.vision_v1p4beta1.types.BoundingPoly]): - Optional. Bounding polygons around the areas - of interest in the reference image. If this - field is empty, the system will try to detect - regions of interest. At most 10 bounding - polygons will be used. - The provided shape is converted into a non- - rotated rectangle. Once converted, the small - edge of the rectangle must be greater than or - equal to 300 pixels. The aspect ratio must be - 1:4 or less (i.e. 1:3 is ok; 1:5 is not). - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - uri = proto.Field( - proto.STRING, - number=2, - ) - bounding_polys = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=geometry.BoundingPoly, - ) - - -class CreateProductRequest(proto.Message): - r"""Request message for the ``CreateProduct`` method. - - Attributes: - parent (str): - Required. The project in which the Product should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product (google.cloud.vision_v1p4beta1.types.Product): - Required. The product to create. - product_id (str): - A user-supplied resource id for this Product. If set, the - server will attempt to use this value as the resource id. If - it is already in use, an error is returned with code - ALREADY_EXISTS. Must be at most 128 characters long. It - cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.MESSAGE, - number=2, - message='Product', - ) - product_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsRequest(proto.Message): - r"""Request message for the ``ListProducts`` method. - - Attributes: - parent (str): - Required. The project OR ProductSet from which Products - should be listed. - - Format: ``projects/PROJECT_ID/locations/LOC_ID`` - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsResponse(proto.Message): - r"""Response message for the ``ListProducts`` method. - - Attributes: - products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): - List of products. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - products = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class GetProductRequest(proto.Message): - r"""Request message for the ``GetProduct`` method. - - Attributes: - name (str): - Required. Resource name of the Product to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateProductRequest(proto.Message): - r"""Request message for the ``UpdateProduct`` method. - - Attributes: - product (google.cloud.vision_v1p4beta1.types.Product): - Required. The Product resource which replaces - the one on the server. product.name is - immutable. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that specifies - which fields to update. If update_mask isn't specified, all - mutable fields are to be updated. Valid mask paths include - ``product_labels``, ``display_name``, and ``description``. - """ - - product = proto.Field( - proto.MESSAGE, - number=1, - message='Product', - ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteProductRequest(proto.Message): - r"""Request message for the ``DeleteProduct`` method. - - Attributes: - name (str): - Required. Resource name of product to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateProductSetRequest(proto.Message): - r"""Request message for the ``CreateProductSet`` method. - - Attributes: - parent (str): - Required. The project in which the ProductSet should be - created. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - product_set (google.cloud.vision_v1p4beta1.types.ProductSet): - Required. The ProductSet to create. - product_set_id (str): - A user-supplied resource id for this ProductSet. If set, the - server will attempt to use this value as the resource id. If - it is already in use, an error is returned with code - ALREADY_EXISTS. Must be at most 128 characters long. It - cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - product_set = proto.Field( - proto.MESSAGE, - number=2, - message='ProductSet', - ) - product_set_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductSetsRequest(proto.Message): - r"""Request message for the ``ListProductSets`` method. - - Attributes: - parent (str): - Required. The project from which ProductSets should be - listed. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductSetsResponse(proto.Message): - r"""Response message for the ``ListProductSets`` method. - - Attributes: - product_sets (Sequence[google.cloud.vision_v1p4beta1.types.ProductSet]): - List of ProductSets. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - product_sets = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ProductSet', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class GetProductSetRequest(proto.Message): - r"""Request message for the ``GetProductSet`` method. - - Attributes: - name (str): - Required. Resource name of the ProductSet to get. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateProductSetRequest(proto.Message): - r"""Request message for the ``UpdateProductSet`` method. - - Attributes: - product_set (google.cloud.vision_v1p4beta1.types.ProductSet): - Required. The ProductSet resource which - replaces the one on the server. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The [FieldMask][google.protobuf.FieldMask] that specifies - which fields to update. If update_mask isn't specified, all - mutable fields are to be updated. Valid mask path is - ``display_name``. - """ - - product_set = proto.Field( - proto.MESSAGE, - number=1, - message='ProductSet', - ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteProductSetRequest(proto.Message): - r"""Request message for the ``DeleteProductSet`` method. - - Attributes: - name (str): - Required. Resource name of the ProductSet to delete. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateReferenceImageRequest(proto.Message): - r"""Request message for the ``CreateReferenceImage`` method. - - Attributes: - parent (str): - Required. Resource name of the product in which to create - the reference image. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - reference_image (google.cloud.vision_v1p4beta1.types.ReferenceImage): - Required. The reference image to create. - If an image ID is specified, it is ignored. - reference_image_id (str): - A user-supplied resource id for the ReferenceImage to be - added. If set, the server will attempt to use this value as - the resource id. If it is already in use, an error is - returned with code ALREADY_EXISTS. Must be at most 128 - characters long. It cannot contain the character ``/``. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - reference_image = proto.Field( - proto.MESSAGE, - number=2, - message='ReferenceImage', - ) - reference_image_id = proto.Field( - proto.STRING, - number=3, - ) - - -class ListReferenceImagesRequest(proto.Message): - r"""Request message for the ``ListReferenceImages`` method. - - Attributes: - parent (str): - Required. Resource name of the product containing the - reference images. - - Format is - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID``. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - A token identifying a page of results to be returned. This - is the value of ``nextPageToken`` returned in a previous - reference image list request. - - Defaults to the first page if not specified. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListReferenceImagesResponse(proto.Message): - r"""Response message for the ``ListReferenceImages`` method. - - Attributes: - reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): - The list of reference images. - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - next_page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - @property - def raw_page(self): - return self - - reference_images = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ReferenceImage', - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - next_page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class GetReferenceImageRequest(proto.Message): - r"""Request message for the ``GetReferenceImage`` method. - - Attributes: - name (str): - Required. The resource name of the ReferenceImage to get. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID``. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class DeleteReferenceImageRequest(proto.Message): - r"""Request message for the ``DeleteReferenceImage`` method. - - Attributes: - name (str): - Required. The resource name of the reference image to - delete. - - Format is: - - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class AddProductToProductSetRequest(proto.Message): - r"""Request message for the ``AddProductToProductSet`` method. - - Attributes: - name (str): - Required. The resource name for the ProductSet to modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - product (str): - Required. The resource name for the Product to be added to - this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.STRING, - number=2, - ) - - -class RemoveProductFromProductSetRequest(proto.Message): - r"""Request message for the ``RemoveProductFromProductSet`` method. - - Attributes: - name (str): - Required. The resource name for the ProductSet to modify. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - product (str): - Required. The resource name for the Product to be removed - from this ProductSet. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`` - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - product = proto.Field( - proto.STRING, - number=2, - ) - - -class ListProductsInProductSetRequest(proto.Message): - r"""Request message for the ``ListProductsInProductSet`` method. - - Attributes: - name (str): - Required. The ProductSet resource for which to retrieve - Products. - - Format is: - ``projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`` - page_size (int): - The maximum number of items to return. - Default 10, maximum 100. - page_token (str): - The next_page_token returned from a previous List request, - if any. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsInProductSetResponse(proto.Message): - r"""Response message for the ``ListProductsInProductSet`` method. - - Attributes: - products (Sequence[google.cloud.vision_v1p4beta1.types.Product]): - The list of Products. - next_page_token (str): - Token to retrieve the next page of results, - or empty if there are no more results in the - list. - """ - - @property - def raw_page(self): - return self - - products = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class ImportProductSetsGcsSource(proto.Message): - r"""The Google Cloud Storage location for a csv file which - preserves a list of ImportProductSetRequests in each line. - - Attributes: - csv_file_uri (str): - The Google Cloud Storage URI of the input csv file. - - The URI must start with ``gs://``. - - The format of the input csv file should be one image per - line. In each line, there are 8 columns. - - 1. image-uri - 2. image-id - 3. product-set-id - 4. product-id - 5. product-category - 6. product-display-name - 7. labels - 8. bounding-poly - - The ``image-uri``, ``product-set-id``, ``product-id``, and - ``product-category`` columns are required. All other columns - are optional. - - If the ``ProductSet`` or ``Product`` specified by the - ``product-set-id`` and ``product-id`` values does not exist, - then the system will create a new ``ProductSet`` or - ``Product`` for the image. In this case, the - ``product-display-name`` column refers to - [display_name][google.cloud.vision.v1p4beta1.Product.display_name], - the ``product-category`` column refers to - [product_category][google.cloud.vision.v1p4beta1.Product.product_category], - and the ``labels`` column refers to - [product_labels][google.cloud.vision.v1p4beta1.Product.product_labels]. - - The ``image-id`` column is optional but must be unique if - provided. If it is empty, the system will automatically - assign a unique id to the image. - - The ``product-display-name`` column is optional. If it is - empty, the system sets the - [display_name][google.cloud.vision.v1p4beta1.Product.display_name] - field for the product to a space (" "). You can update the - ``display_name`` later by using the API. - - If a ``Product`` with the specified ``product-id`` already - exists, then the system ignores the - ``product-display-name``, ``product-category``, and - ``labels`` columns. - - The ``labels`` column (optional) is a line containing a list - of comma-separated key-value pairs, in the following format: - - :: - - "key_1=value_1,key_2=value_2,...,key_n=value_n" - - The ``bounding-poly`` column (optional) identifies one - region of interest from the image in the same manner as - ``CreateReferenceImage``. If you do not specify the - ``bounding-poly`` column, then the system will try to detect - regions of interest automatically. - - At most one ``bounding-poly`` column is allowed per line. If - the image contains multiple regions of interest, add a line - to the CSV file that includes the same product information, - and the ``bounding-poly`` values for each region of - interest. - - The ``bounding-poly`` column must contain an even number of - comma-separated numbers, in the format - "p1_x,p1_y,p2_x,p2_y,...,pn_x,pn_y". Use non-negative - integers for absolute bounding polygons, and float values in - [0, 1] for normalized bounding polygons. - - The system will resize the image if the image resolution is - too large to process (larger than 20MP). - """ - - csv_file_uri = proto.Field( - proto.STRING, - number=1, - ) - - -class ImportProductSetsInputConfig(proto.Message): - r"""The input content for the ``ImportProductSets`` method. - - Attributes: - gcs_source (google.cloud.vision_v1p4beta1.types.ImportProductSetsGcsSource): - The Google Cloud Storage location for a csv - file which preserves a list of - ImportProductSetRequests in each line. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - oneof='source', - message='ImportProductSetsGcsSource', - ) - - -class ImportProductSetsRequest(proto.Message): - r"""Request message for the ``ImportProductSets`` method. - - Attributes: - parent (str): - Required. The project in which the ProductSets should be - imported. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - input_config (google.cloud.vision_v1p4beta1.types.ImportProductSetsInputConfig): - Required. The input content for the list of - requests. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - input_config = proto.Field( - proto.MESSAGE, - number=2, - message='ImportProductSetsInputConfig', - ) - - -class ImportProductSetsResponse(proto.Message): - r"""Response message for the ``ImportProductSets`` method. - - This message is returned by the - [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] - method in the returned - [google.longrunning.Operation.response][google.longrunning.Operation.response] - field. - - Attributes: - reference_images (Sequence[google.cloud.vision_v1p4beta1.types.ReferenceImage]): - The list of reference_images that are imported successfully. - statuses (Sequence[google.rpc.status_pb2.Status]): - The rpc status for each ImportProductSet request, including - both successes and errors. - - The number of statuses here matches the number of lines in - the csv file, and statuses[i] stores the success or failure - status of processing the i-th line of the csv, starting from - line 0. - """ - - reference_images = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ReferenceImage', - ) - statuses = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=status_pb2.Status, - ) - - -class BatchOperationMetadata(proto.Message): - r"""Metadata for the batch operations such as the current state. - - This is included in the ``metadata`` field of the ``Operation`` - returned by the ``GetOperation`` call of the - ``google::longrunning::Operations`` service. - - Attributes: - state (google.cloud.vision_v1p4beta1.types.BatchOperationMetadata.State): - The current state of the batch operation. - submit_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request was submitted - to the server. - end_time (google.protobuf.timestamp_pb2.Timestamp): - The time when the batch request is finished and - [google.longrunning.Operation.done][google.longrunning.Operation.done] - is set to true. - """ - class State(proto.Enum): - r"""Enumerates the possible states that the batch request can be - in. - """ - STATE_UNSPECIFIED = 0 - PROCESSING = 1 - SUCCESSFUL = 2 - FAILED = 3 - CANCELLED = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - submit_time = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - end_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -class ProductSetPurgeConfig(proto.Message): - r"""Config to control which ProductSet contains the Products to - be deleted. - - Attributes: - product_set_id (str): - The ProductSet that contains the Products to delete. If a - Product is a member of product_set_id in addition to other - ProductSets, the Product will still be deleted. - """ - - product_set_id = proto.Field( - proto.STRING, - number=1, - ) - - -class PurgeProductsRequest(proto.Message): - r"""Request message for the ``PurgeProducts`` method. - - Attributes: - product_set_purge_config (google.cloud.vision_v1p4beta1.types.ProductSetPurgeConfig): - Specify which ProductSet contains the - Products to be deleted. - delete_orphan_products (bool): - If delete_orphan_products is true, all Products that are not - in any ProductSet will be deleted. - parent (str): - Required. The project and location in which the Products - should be deleted. - - Format is ``projects/PROJECT_ID/locations/LOC_ID``. - force (bool): - The default value is false. Override this - value to true to actually perform the purge. - """ - - product_set_purge_config = proto.Field( - proto.MESSAGE, - number=2, - oneof='target', - message='ProductSetPurgeConfig', - ) - delete_orphan_products = proto.Field( - proto.BOOL, - number=3, - oneof='target', - ) - parent = proto.Field( - proto.STRING, - number=1, - ) - force = proto.Field( - proto.BOOL, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py deleted file mode 100644 index 09ebaef0..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/text_annotation.py +++ /dev/null @@ -1,393 +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.vision_v1p4beta1.types import geometry - - -__protobuf__ = proto.module( - package='google.cloud.vision.v1p4beta1', - manifest={ - 'TextAnnotation', - 'Page', - 'Block', - 'Paragraph', - 'Word', - 'Symbol', - }, -) - - -class TextAnnotation(proto.Message): - r"""TextAnnotation contains a structured representation of OCR extracted - text. The hierarchy of an OCR extracted text structure is like this: - TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol Each - structural component, starting from Page, may further have their own - properties. Properties describe detected languages, breaks etc.. - Please refer to the - [TextAnnotation.TextProperty][google.cloud.vision.v1p4beta1.TextAnnotation.TextProperty] - message definition below for more detail. - - Attributes: - pages (Sequence[google.cloud.vision_v1p4beta1.types.Page]): - List of pages detected by OCR. - text (str): - UTF-8 text detected on the pages. - """ - - 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, - ) - - class DetectedBreak(proto.Message): - r"""Detected start or end of a structural component. - - Attributes: - type_ (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak.BreakType): - Detected break type. - is_prefix (bool): - True if break prepends the element. - """ - class BreakType(proto.Enum): - r"""Enum to denote the type of break found. New line, space etc.""" - UNKNOWN = 0 - SPACE = 1 - SURE_SPACE = 2 - EOL_SURE_SPACE = 3 - HYPHEN = 4 - LINE_BREAK = 5 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='TextAnnotation.DetectedBreak.BreakType', - ) - is_prefix = proto.Field( - proto.BOOL, - number=2, - ) - - class TextProperty(proto.Message): - r"""Additional information detected on the structural component. - - Attributes: - detected_languages (Sequence[google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedLanguage]): - A list of detected languages together with - confidence. - detected_break (google.cloud.vision_v1p4beta1.types.TextAnnotation.DetectedBreak): - Detected start or end of a text segment. - """ - - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='TextAnnotation.DetectedLanguage', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='TextAnnotation.DetectedBreak', - ) - - pages = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Page', - ) - text = proto.Field( - proto.STRING, - number=2, - ) - - -class Page(proto.Message): - r"""Detected page from OCR. - - Attributes: - property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): - Additional information detected on the page. - width (int): - Page width. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - height (int): - Page height. For PDFs the unit is points. For - images (including TIFFs) the unit is pixels. - blocks (Sequence[google.cloud.vision_v1p4beta1.types.Block]): - List of blocks of text, images etc on this - page. - confidence (float): - Confidence of the OCR results on the page. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - width = proto.Field( - proto.INT32, - number=2, - ) - height = proto.Field( - proto.INT32, - number=3, - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Block', - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Block(proto.Message): - r"""Logical element on the page. - - Attributes: - property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - block. - bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding box for the block. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: - - :: - - 0----1 - | | - 3----2 - - - when it's rotated 180 degrees around the top-left corner - it becomes: - - :: - - 2----3 - | | - 1----0 - - and the vertex order will still be (0, 1, 2, 3). - paragraphs (Sequence[google.cloud.vision_v1p4beta1.types.Paragraph]): - List of paragraphs in this block (if this - blocks is of type text). - block_type (google.cloud.vision_v1p4beta1.types.Block.BlockType): - Detected block type (text, image etc) for - this block. - confidence (float): - Confidence of the OCR results on the block. Range [0, 1]. - """ - class BlockType(proto.Enum): - r"""Type of a block (text, image etc) as identified by OCR.""" - UNKNOWN = 0 - TEXT = 1 - TABLE = 2 - PICTURE = 3 - RULER = 4 - BARCODE = 5 - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Paragraph', - ) - block_type = proto.Field( - proto.ENUM, - number=4, - enum=BlockType, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - -class Paragraph(proto.Message): - r"""Structural unit of text representing a number of words in - certain order. - - Attributes: - property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - paragraph. - bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding box for the paragraph. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). - words (Sequence[google.cloud.vision_v1p4beta1.types.Word]): - List of all words in this paragraph. - confidence (float): - Confidence of the OCR results for the paragraph. Range [0, - 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - words = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Word', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Word(proto.Message): - r"""A word representation. - - Attributes: - property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): - Additional information detected for the word. - bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding box for the word. The vertices are in the order - of top-left, top-right, bottom-right, bottom-left. When a - rotation of the bounding box is detected the rotation is - represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). - symbols (Sequence[google.cloud.vision_v1p4beta1.types.Symbol]): - List of symbols in the word. - The order of the symbols follows the natural - reading order. - confidence (float): - Confidence of the OCR results for the word. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - symbols = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Symbol', - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -class Symbol(proto.Message): - r"""A single symbol representation. - - Attributes: - property (google.cloud.vision_v1p4beta1.types.TextAnnotation.TextProperty): - Additional information detected for the - symbol. - bounding_box (google.cloud.vision_v1p4beta1.types.BoundingPoly): - The bounding box for the symbol. The vertices are in the - order of top-left, top-right, bottom-right, bottom-left. - When a rotation of the bounding box is detected the rotation - is represented as around the top-left corner as defined when - the text is read in the 'natural' orientation. For example: - - - when the text is horizontal it might look like: 0----1 \| - \| 3----2 - - when it's rotated 180 degrees around the top-left corner - it becomes: 2----3 \| \| 1----0 and the vertex order will - still be (0, 1, 2, 3). - text (str): - The actual UTF-8 representation of the - symbol. - confidence (float): - Confidence of the OCR results for the symbol. Range [0, 1]. - """ - - property = proto.Field( - proto.MESSAGE, - number=1, - message='TextAnnotation.TextProperty', - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - text = proto.Field( - proto.STRING, - number=3, - ) - confidence = proto.Field( - proto.FLOAT, - number=4, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py b/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py deleted file mode 100644 index 15b2d359..00000000 --- a/owl-bot-staging/v1p4beta1/google/cloud/vision_v1p4beta1/types/web_detection.py +++ /dev/null @@ -1,201 +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.vision.v1p4beta1', - manifest={ - 'WebDetection', - }, -) - - -class WebDetection(proto.Message): - r"""Relevant information for the image from the Internet. - - Attributes: - web_entities (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebEntity]): - Deduced entities from similar images on the - Internet. - full_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): - Fully matching images from the Internet. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): - Partial matching images from the Internet. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - pages_with_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebPage]): - Web pages containing the matching images from - the Internet. - visually_similar_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): - The visually similar image results. - best_guess_labels (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebLabel]): - The service's best guess as to the topic of - the request image. Inferred from similar images - on the open web. - """ - - class WebEntity(proto.Message): - r"""Entity deduced from similar images on the Internet. - - Attributes: - entity_id (str): - Opaque entity ID. - score (float): - Overall relevancy score for the entity. - Not normalized and not comparable across - different image queries. - description (str): - Canonical description of the entity, in - English. - """ - - entity_id = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - description = proto.Field( - proto.STRING, - number=3, - ) - - class WebImage(proto.Message): - r"""Metadata for online images. - - Attributes: - url (str): - The result image URL. - score (float): - (Deprecated) Overall relevancy score for the - image. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - - class WebPage(proto.Message): - r"""Metadata for web pages. - - Attributes: - url (str): - The result web page URL. - score (float): - (Deprecated) Overall relevancy score for the - web page. - page_title (str): - Title for the web page, may contain HTML - markups. - full_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): - Fully matching images on the page. - Can include resized copies of the query image. - partial_matching_images (Sequence[google.cloud.vision_v1p4beta1.types.WebDetection.WebImage]): - Partial matching images on the page. - Those images are similar enough to share some - key-point features. For example an original - image will likely have partial matching for its - crops. - """ - - url = proto.Field( - proto.STRING, - number=1, - ) - score = proto.Field( - proto.FLOAT, - number=2, - ) - page_title = proto.Field( - proto.STRING, - number=3, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='WebDetection.WebImage', - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='WebDetection.WebImage', - ) - - class WebLabel(proto.Message): - r"""Label to provide extra metadata for the web detection. - - Attributes: - label (str): - Label for extra metadata. - language_code (str): - The BCP-47 language code for ``label``, such as "en-US" or - "sr-Latn". For more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - """ - - label = proto.Field( - proto.STRING, - number=1, - ) - language_code = proto.Field( - proto.STRING, - number=2, - ) - - web_entities = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=WebEntity, - ) - full_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=WebImage, - ) - partial_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=WebImage, - ) - pages_with_matching_images = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=WebPage, - ) - visually_similar_images = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=WebImage, - ) - best_guess_labels = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=WebLabel, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1p4beta1/mypy.ini b/owl-bot-staging/v1p4beta1/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1p4beta1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1p4beta1/noxfile.py b/owl-bot-staging/v1p4beta1/noxfile.py deleted file mode 100644 index d34812ed..00000000 --- a/owl-bot-staging/v1p4beta1/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/vision_v1p4beta1/', - '--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/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py b/owl-bot-staging/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py deleted file mode 100644 index 70e802a1..00000000 --- a/owl-bot-staging/v1p4beta1/scripts/fixup_vision_v1p4beta1_keywords.py +++ /dev/null @@ -1,198 +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 visionCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'add_product_to_product_set': ('name', 'product', ), - 'async_batch_annotate_files': ('requests', ), - 'async_batch_annotate_images': ('requests', 'output_config', ), - 'batch_annotate_files': ('requests', ), - 'batch_annotate_images': ('requests', ), - 'create_product': ('parent', 'product', 'product_id', ), - 'create_product_set': ('parent', 'product_set', 'product_set_id', ), - 'create_reference_image': ('parent', 'reference_image', 'reference_image_id', ), - 'delete_product': ('name', ), - 'delete_product_set': ('name', ), - 'delete_reference_image': ('name', ), - 'get_product': ('name', ), - 'get_product_set': ('name', ), - 'get_reference_image': ('name', ), - 'import_product_sets': ('parent', 'input_config', ), - 'list_products': ('parent', 'page_size', 'page_token', ), - 'list_product_sets': ('parent', 'page_size', 'page_token', ), - 'list_products_in_product_set': ('name', 'page_size', 'page_token', ), - 'list_reference_images': ('parent', 'page_size', 'page_token', ), - 'purge_products': ('parent', 'product_set_purge_config', 'delete_orphan_products', 'force', ), - 'remove_product_from_product_set': ('name', 'product', ), - 'update_product': ('product', 'update_mask', ), - 'update_product_set': ('product_set', 'update_mask', ), - } - - 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: a.keyword.value not 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=visionCallTransformer(), -): - """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 vision 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/v1p4beta1/setup.py b/owl-bot-staging/v1p4beta1/setup.py deleted file mode 100644 index 9d03e702..00000000 --- a/owl-bot-staging/v1p4beta1/setup.py +++ /dev/null @@ -1,54 +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-vision', - 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, < 3.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', - 'Programming Language :: Python :: 3.9', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1p4beta1/tests/__init__.py b/owl-bot-staging/v1p4beta1/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p4beta1/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/v1p4beta1/tests/unit/__init__.py b/owl-bot-staging/v1p4beta1/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p4beta1/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/v1p4beta1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p4beta1/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/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__init__.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/__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/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py deleted file mode 100644 index 708f48c0..00000000 --- a/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ /dev/null @@ -1,1724 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1p4beta1.services.image_annotator import ImageAnnotatorAsyncClient -from google.cloud.vision_v1p4beta1.services.image_annotator import ImageAnnotatorClient -from google.cloud.vision_v1p4beta1.services.image_annotator import transports -from google.cloud.vision_v1p4beta1.services.image_annotator.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1p4beta1.types import face -from google.cloud.vision_v1p4beta1.types import geometry -from google.cloud.vision_v1p4beta1.types import image_annotator -from google.cloud.vision_v1p4beta1.types import product_search -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.type import latlng_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 ImageAnnotatorClient._get_default_mtls_endpoint(None) is None - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ImageAnnotatorClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ImageAnnotatorGrpcTransport, "grpc"), - (transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ImageAnnotatorClient, - ImageAnnotatorAsyncClient, -]) -def test_image_annotator_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 == 'vision.googleapis.com:443' - - -def test_image_annotator_client_get_transport_class(): - transport = ImageAnnotatorClient.get_transport_class() - available_transports = [ - transports.ImageAnnotatorGrpcTransport, - ] - assert transport in available_transports - - transport = ImageAnnotatorClient.get_transport_class("grpc") - assert transport == transports.ImageAnnotatorGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -def test_image_annotator_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(ImageAnnotatorClient, '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(ImageAnnotatorClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "true"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc", "false"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ImageAnnotatorClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorClient)) -@mock.patch.object(ImageAnnotatorAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ImageAnnotatorAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ImageAnnotatorClient, transports.ImageAnnotatorGrpcTransport, "grpc"), - (ImageAnnotatorAsyncClient, transports.ImageAnnotatorGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_image_annotator_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, - always_use_jwt_access=True, - ) - - -def test_image_annotator_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ImageAnnotatorClient( - 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, - always_use_jwt_access=True, - ) - - -def test_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse( - ) - response = client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -def test_batch_annotate_images_from_dict(): - test_batch_annotate_images(request_type=dict) - - -def test_batch_annotate_images_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 = ImageAnnotatorClient( - 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_annotate_images), - '__call__') as call: - client.batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse( - )) - response = await client.batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateImagesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_async_from_dict(): - await test_batch_annotate_images_async(request_type=dict) - - -def test_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -def test_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - # 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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - - -@pytest.mark.asyncio -async def test_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_images( - image_annotator.BatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - ) - - -def test_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.BatchAnnotateFilesRequest): - client = ImageAnnotatorClient( - 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_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateFilesResponse( - ) - response = client.batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) - - -def test_batch_annotate_files_from_dict(): - test_batch_annotate_files(request_type=dict) - - -def test_batch_annotate_files_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 = ImageAnnotatorClient( - 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_annotate_files), - '__call__') as call: - client.batch_annotate_files() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateFilesRequest() - - -@pytest.mark.asyncio -async def test_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.BatchAnnotateFilesRequest): - client = ImageAnnotatorAsyncClient( - 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_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse( - )) - response = await client.batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.BatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, image_annotator.BatchAnnotateFilesResponse) - - -@pytest.mark.asyncio -async def test_batch_annotate_files_async_from_dict(): - await test_batch_annotate_files_async(request_type=dict) - - -def test_batch_annotate_files_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateFilesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_annotate_files( - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -def test_batch_annotate_files_flattened_error(): - client = ImageAnnotatorClient( - 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_annotate_files( - image_annotator.BatchAnnotateFilesRequest(), - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -@pytest.mark.asyncio -async def test_batch_annotate_files_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = image_annotator.BatchAnnotateFilesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(image_annotator.BatchAnnotateFilesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_annotate_files( - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -@pytest.mark.asyncio -async def test_batch_annotate_files_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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_annotate_files( - image_annotator.BatchAnnotateFilesRequest(), - requests=[image_annotator.AnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -def test_async_batch_annotate_images(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): - client = ImageAnnotatorClient( - 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.async_batch_annotate_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.async_batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_async_batch_annotate_images_from_dict(): - test_async_batch_annotate_images(request_type=dict) - - -def test_async_batch_annotate_images_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 = ImageAnnotatorClient( - 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.async_batch_annotate_images), - '__call__') as call: - client.async_batch_annotate_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateImagesRequest): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_images), - '__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.async_batch_annotate_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_async_from_dict(): - await test_async_batch_annotate_images_async(request_type=dict) - - -def test_async_batch_annotate_images_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_images), - '__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.async_batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) - - -def test_async_batch_annotate_images_flattened_error(): - client = ImageAnnotatorClient( - 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.async_batch_annotate_images( - image_annotator.AsyncBatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), - ) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_images), - '__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.async_batch_annotate_images( - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_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 == [image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))] - assert args[0].output_config == image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_images_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_images( - image_annotator.AsyncBatchAnnotateImagesRequest(), - requests=[image_annotator.AnnotateImageRequest(image=image_annotator.Image(content=b'content_blob'))], - output_config=image_annotator.OutputConfig(gcs_destination=image_annotator.GcsDestination(uri='uri_value')), - ) - - -def test_async_batch_annotate_files(transport: str = 'grpc', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_async_batch_annotate_files_from_dict(): - test_async_batch_annotate_files(request_type=dict) - - -def test_async_batch_annotate_files_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 = ImageAnnotatorClient( - 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.async_batch_annotate_files), - '__call__') as call: - client.async_batch_annotate_files() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async(transport: str = 'grpc_asyncio', request_type=image_annotator.AsyncBatchAnnotateFilesRequest): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files), - '__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.async_batch_annotate_files(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == image_annotator.AsyncBatchAnnotateFilesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_async_from_dict(): - await test_async_batch_annotate_files_async(request_type=dict) - - -def test_async_batch_annotate_files_flattened(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -def test_async_batch_annotate_files_flattened_error(): - client = ImageAnnotatorClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.async_batch_annotate_files), - '__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.async_batch_annotate_files( - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_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 == [image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))] - - -@pytest.mark.asyncio -async def test_async_batch_annotate_files_flattened_error_async(): - client = ImageAnnotatorAsyncClient( - 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.async_batch_annotate_files( - image_annotator.AsyncBatchAnnotateFilesRequest(), - requests=[image_annotator.AsyncAnnotateFileRequest(input_config=image_annotator.InputConfig(gcs_source=image_annotator.GcsSource(uri='uri_value')))], - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ImageAnnotatorClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ImageAnnotatorClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ImageAnnotatorGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, -]) -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 = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ImageAnnotatorGrpcTransport, - ) - -def test_image_annotator_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_image_annotator_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ImageAnnotatorTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'batch_annotate_images', - 'batch_annotate_files', - 'async_batch_annotate_images', - 'async_batch_annotate_files', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_image_annotator_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.vision_v1p4beta1.services.image_annotator.transports.ImageAnnotatorTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ImageAnnotatorTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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) - ImageAnnotatorClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_image_annotator_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ImageAnnotatorGrpcTransport, - transports.ImageAnnotatorGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_image_annotator_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ImageAnnotatorGrpcTransport, grpc_helpers), - (transports.ImageAnnotatorGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_image_annotator_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_host_no_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_image_annotator_host_with_port(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_image_annotator_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcTransport( - 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_image_annotator_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ImageAnnotatorGrpcAsyncIOTransport( - 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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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.ImageAnnotatorGrpcTransport, transports.ImageAnnotatorGrpcAsyncIOTransport]) -def test_image_annotator_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_image_annotator_grpc_lro_client(): - client = ImageAnnotatorClient( - 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_image_annotator_grpc_lro_async_client(): - client = ImageAnnotatorAsyncClient( - 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_product_path(): - project = "squid" - location = "clam" - product = "whelk" - expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - actual = ImageAnnotatorClient.product_path(project, location, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "project": "octopus", - "location": "oyster", - "product": "nudibranch", - } - path = ImageAnnotatorClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_product_path(path) - assert expected == actual - -def test_product_set_path(): - project = "cuttlefish" - location = "mussel" - product_set = "winkle" - expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - actual = ImageAnnotatorClient.product_set_path(project, location, product_set) - assert expected == actual - - -def test_parse_product_set_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "product_set": "abalone", - } - path = ImageAnnotatorClient.product_set_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_product_set_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ImageAnnotatorClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ImageAnnotatorClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = ImageAnnotatorClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ImageAnnotatorClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ImageAnnotatorClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ImageAnnotatorClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = ImageAnnotatorClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ImageAnnotatorClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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 = ImageAnnotatorClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ImageAnnotatorClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ImageAnnotatorClient.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.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ImageAnnotatorTransport, '_prep_wrapped_messages') as prep: - transport_class = ImageAnnotatorClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ImageAnnotatorAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ImageAnnotatorClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py deleted file mode 100644 index 38de16ac..00000000 --- a/owl-bot-staging/v1p4beta1/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ /dev/null @@ -1,6323 +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.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.vision_v1p4beta1.services.product_search import ProductSearchAsyncClient -from google.cloud.vision_v1p4beta1.services.product_search import ProductSearchClient -from google.cloud.vision_v1p4beta1.services.product_search import pagers -from google.cloud.vision_v1p4beta1.services.product_search import transports -from google.cloud.vision_v1p4beta1.services.product_search.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.vision_v1p4beta1.types import geometry -from google.cloud.vision_v1p4beta1.types import product_search_service -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -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 ProductSearchClient._get_default_mtls_endpoint(None) is None - assert ProductSearchClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductSearchClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - ProductSearchClient, - ProductSearchAsyncClient, -]) -def test_product_search_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 == 'vision.googleapis.com:443' - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductSearchGrpcTransport, "grpc"), - (transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_client_service_account_always_use_jwt(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) - - 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=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class", [ - ProductSearchClient, - ProductSearchAsyncClient, -]) -def test_product_search_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 == 'vision.googleapis.com:443' - - -def test_product_search_client_get_transport_class(): - transport = ProductSearchClient.get_transport_class() - available_transports = [ - transports.ProductSearchGrpcTransport, - ] - assert transport in available_transports - - transport = ProductSearchClient.get_transport_class("grpc") - assert transport == transports.ProductSearchGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) -@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) -def test_product_search_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(ProductSearchClient, '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(ProductSearchClient, '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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "true"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc", "false"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(ProductSearchClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchClient)) -@mock.patch.object(ProductSearchAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductSearchAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_product_search_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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - # 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, - always_use_jwt_access=True, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_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, - always_use_jwt_access=True, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductSearchClient, transports.ProductSearchGrpcTransport, "grpc"), - (ProductSearchAsyncClient, transports.ProductSearchGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_product_search_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, - always_use_jwt_access=True, - ) - - -def test_product_search_client_client_options_from_dict(): - with mock.patch('google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ProductSearchClient( - 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, - always_use_jwt_access=True, - ) - - -def test_create_product_set(transport: str = 'grpc', request_type=product_search_service.CreateProductSetRequest): - client = ProductSearchClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.create_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_create_product_set_from_dict(): - test_create_product_set(request_type=dict) - - -def test_create_product_set_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 = ProductSearchClient( - 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_product_set), - '__call__') as call: - client.create_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - -@pytest.mark.asyncio -async def test_create_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductSetRequest): - client = ProductSearchAsyncClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.create_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_create_product_set_async_from_dict(): - await test_create_product_set_async(request_type=dict) - - -def test_create_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateProductSetRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.create_product_set(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_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateProductSetRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.create_product_set(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_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_product_set( - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].product_set_id == 'product_set_id_value' - - -def test_create_product_set_flattened_error(): - client = ProductSearchClient( - 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_product_set( - product_search_service.CreateProductSetRequest(), - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_product_set( - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].product_set_id == 'product_set_id_value' - - -@pytest.mark.asyncio -async def test_create_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_set( - product_search_service.CreateProductSetRequest(), - parent='parent_value', - product_set=product_search_service.ProductSet(name='name_value'), - product_set_id='product_set_id_value', - ) - - -def test_list_product_sets(transport: str = 'grpc', request_type=product_search_service.ListProductSetsRequest): - client = ProductSearchClient( - 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_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductSetsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_product_sets_from_dict(): - test_list_product_sets(request_type=dict) - - -def test_list_product_sets_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 = ProductSearchClient( - 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_product_sets), - '__call__') as call: - client.list_product_sets() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - -@pytest.mark.asyncio -async def test_list_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductSetsRequest): - client = ProductSearchAsyncClient( - 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_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductSetsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_product_sets_async_from_dict(): - await test_list_product_sets_async(request_type=dict) - - -def test_list_product_sets_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - call.return_value = product_search_service.ListProductSetsResponse() - client.list_product_sets(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_product_sets_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) - await client.list_product_sets(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_product_sets_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_product_sets( - 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_product_sets_flattened_error(): - client = ProductSearchClient( - 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_product_sets( - product_search_service.ListProductSetsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_product_sets_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductSetsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductSetsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_product_sets( - 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_product_sets_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_sets( - product_search_service.ListProductSetsRequest(), - parent='parent_value', - ) - - -def test_list_product_sets_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_product_sets(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.ProductSet) - for i in results) - -def test_list_product_sets_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - pages = list(client.list_product_sets(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_product_sets_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_product_sets(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, product_search_service.ProductSet) - for i in responses) - -@pytest.mark.asyncio -async def test_list_product_sets_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_product_sets), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - next_page_token='abc', - ), - product_search_service.ListProductSetsResponse( - product_sets=[], - next_page_token='def', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductSetsResponse( - product_sets=[ - product_search_service.ProductSet(), - product_search_service.ProductSet(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_product_sets(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_product_set(transport: str = 'grpc', request_type=product_search_service.GetProductSetRequest): - client = ProductSearchClient( - 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.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.get_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_get_product_set_from_dict(): - test_get_product_set(request_type=dict) - - -def test_get_product_set_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 = ProductSearchClient( - 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.get_product_set), - '__call__') as call: - client.get_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - -@pytest.mark.asyncio -async def test_get_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductSetRequest): - client = ProductSearchAsyncClient( - 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.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.get_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_get_product_set_async_from_dict(): - await test_get_product_set_async(request_type=dict) - - -def test_get_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.get_product_set(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_get_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.get_product_set(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_get_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product_set( - 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_get_product_set_flattened_error(): - client = ProductSearchClient( - 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.get_product_set( - product_search_service.GetProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product_set( - 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_get_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_product_set( - product_search_service.GetProductSetRequest(), - name='name_value', - ) - - -def test_update_product_set(transport: str = 'grpc', request_type=product_search_service.UpdateProductSetRequest): - client = ProductSearchClient( - 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.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - ) - response = client.update_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -def test_update_product_set_from_dict(): - test_update_product_set(request_type=dict) - - -def test_update_product_set_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 = ProductSearchClient( - 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.update_product_set), - '__call__') as call: - client.update_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - -@pytest.mark.asyncio -async def test_update_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductSetRequest): - client = ProductSearchAsyncClient( - 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.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet( - name='name_value', - display_name='display_name_value', - )) - response = await client.update_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ProductSet) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - - -@pytest.mark.asyncio -async def test_update_product_set_async_from_dict(): - await test_update_product_set_async(request_type=dict) - - -def test_update_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.UpdateProductSetRequest() - - request.product_set.name = 'product_set.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - call.return_value = product_search_service.ProductSet() - client.update_product_set(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', - 'product_set.name=product_set.name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.UpdateProductSetRequest() - - request.product_set.name = 'product_set.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - await client.update_product_set(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', - 'product_set.name=product_set.name/value', - ) in kw['metadata'] - - -def test_update_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product_set( - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -def test_update_product_set_flattened_error(): - client = ProductSearchClient( - 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.update_product_set( - product_search_service.UpdateProductSetRequest(), - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.asyncio -async def test_update_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ProductSet() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ProductSet()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product_set( - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product_set == product_search_service.ProductSet(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -@pytest.mark.asyncio -async def test_update_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.update_product_set( - product_search_service.UpdateProductSetRequest(), - product_set=product_search_service.ProductSet(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product_set(transport: str = 'grpc', request_type=product_search_service.DeleteProductSetRequest): - client = ProductSearchClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_set_from_dict(): - test_delete_product_set(request_type=dict) - - -def test_delete_product_set_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 = ProductSearchClient( - 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_product_set), - '__call__') as call: - client.delete_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - -@pytest.mark.asyncio -async def test_delete_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductSetRequest): - client = ProductSearchAsyncClient( - 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_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_set_async_from_dict(): - await test_delete_product_set_async(request_type=dict) - - -def test_delete_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - call.return_value = None - client.delete_product_set(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_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product_set(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_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product_set( - 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_product_set_flattened_error(): - client = ProductSearchClient( - 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_product_set( - product_search_service.DeleteProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product_set( - 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_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product_set( - product_search_service.DeleteProductSetRequest(), - name='name_value', - ) - - -def test_create_product(transport: str = 'grpc', request_type=product_search_service.CreateProductRequest): - client = ProductSearchClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.create_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_create_product_from_dict(): - test_create_product(request_type=dict) - - -def test_create_product_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 = ProductSearchClient( - 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_product), - '__call__') as call: - client.create_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - -@pytest.mark.asyncio -async def test_create_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateProductRequest): - client = ProductSearchAsyncClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.create_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_create_product_async_from_dict(): - await test_create_product_async(request_type=dict) - - -def test_create_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateProductRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.create_product(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_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateProductRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.create_product(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_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_product( - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_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].product == product_search_service.Product(name='name_value') - assert args[0].product_id == 'product_id_value' - - -def test_create_product_flattened_error(): - client = ProductSearchClient( - 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_product( - product_search_service.CreateProductRequest(), - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_product( - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_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].product == product_search_service.Product(name='name_value') - assert args[0].product_id == 'product_id_value' - - -@pytest.mark.asyncio -async def test_create_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product( - product_search_service.CreateProductRequest(), - parent='parent_value', - product=product_search_service.Product(name='name_value'), - product_id='product_id_value', - ) - - -def test_list_products(transport: str = 'grpc', request_type=product_search_service.ListProductsRequest): - client = ProductSearchClient( - 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_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_from_dict(): - test_list_products(request_type=dict) - - -def test_list_products_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 = ProductSearchClient( - 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_products), - '__call__') as call: - client.list_products() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - -@pytest.mark.asyncio -async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsRequest): - client = ProductSearchAsyncClient( - 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_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_async_from_dict(): - await test_list_products_async(request_type=dict) - - -def test_list_products_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = product_search_service.ListProductsResponse() - client.list_products(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_products_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) - await client.list_products(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_products_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products( - 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_products_flattened_error(): - client = ProductSearchClient( - 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_products( - product_search_service.ListProductsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_products_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products( - 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_products_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_products( - product_search_service.ListProductsRequest(), - parent='parent_value', - ) - - -def test_list_products_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_products(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.Product) - for i in results) - -def test_list_products_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products(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_products_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products(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, product_search_service.Product) - for i in responses) - -@pytest.mark.asyncio -async def test_list_products_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_products(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_product(transport: str = 'grpc', request_type=product_search_service.GetProductRequest): - client = ProductSearchClient( - 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.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_get_product_from_dict(): - test_get_product(request_type=dict) - - -def test_get_product_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 = ProductSearchClient( - 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.get_product), - '__call__') as call: - client.get_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - -@pytest.mark.asyncio -async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetProductRequest): - client = ProductSearchAsyncClient( - 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.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_get_product_async_from_dict(): - await test_get_product_async(request_type=dict) - - -def test_get_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.get_product(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_get_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.get_product(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_get_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product( - 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_get_product_flattened_error(): - client = ProductSearchClient( - 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.get_product( - product_search_service.GetProductRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product( - 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_get_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_product( - product_search_service.GetProductRequest(), - name='name_value', - ) - - -def test_update_product(transport: str = 'grpc', request_type=product_search_service.UpdateProductRequest): - client = ProductSearchClient( - 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.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - ) - response = client.update_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -def test_update_product_from_dict(): - test_update_product(request_type=dict) - - -def test_update_product_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 = ProductSearchClient( - 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.update_product), - '__call__') as call: - client.update_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - -@pytest.mark.asyncio -async def test_update_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.UpdateProductRequest): - client = ProductSearchAsyncClient( - 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.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product( - name='name_value', - display_name='display_name_value', - description='description_value', - product_category='product_category_value', - )) - response = await client.update_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.UpdateProductRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.Product) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.description == 'description_value' - assert response.product_category == 'product_category_value' - - -@pytest.mark.asyncio -async def test_update_product_async_from_dict(): - await test_update_product_async(request_type=dict) - - -def test_update_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.UpdateProductRequest() - - request.product.name = 'product.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - call.return_value = product_search_service.Product() - client.update_product(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', - 'product.name=product.name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.UpdateProductRequest() - - request.product.name = 'product.name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - await client.update_product(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', - 'product.name=product.name/value', - ) in kw['metadata'] - - -def test_update_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product( - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -def test_update_product_flattened_error(): - client = ProductSearchClient( - 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.update_product( - product_search_service.UpdateProductRequest(), - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.asyncio -async def test_update_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product( - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_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].product == product_search_service.Product(name='name_value') - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=['paths_value']) - - -@pytest.mark.asyncio -async def test_update_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.update_product( - product_search_service.UpdateProductRequest(), - product=product_search_service.Product(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product(transport: str = 'grpc', request_type=product_search_service.DeleteProductRequest): - client = ProductSearchClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_from_dict(): - test_delete_product(request_type=dict) - - -def test_delete_product_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 = ProductSearchClient( - 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_product), - '__call__') as call: - client.delete_product() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - -@pytest.mark.asyncio -async def test_delete_product_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteProductRequest): - client = ProductSearchAsyncClient( - 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_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteProductRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_async_from_dict(): - await test_delete_product_async(request_type=dict) - - -def test_delete_product_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - call.return_value = None - client.delete_product(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_product_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteProductRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product(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_product_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product( - 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_product_flattened_error(): - client = ProductSearchClient( - 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_product( - product_search_service.DeleteProductRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_product_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product( - 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_product_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_product( - product_search_service.DeleteProductRequest(), - name='name_value', - ) - - -def test_create_reference_image(transport: str = 'grpc', request_type=product_search_service.CreateReferenceImageRequest): - client = ProductSearchClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - ) - response = client.create_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -def test_create_reference_image_from_dict(): - test_create_reference_image(request_type=dict) - - -def test_create_reference_image_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 = ProductSearchClient( - 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_reference_image), - '__call__') as call: - client.create_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_create_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.CreateReferenceImageRequest): - client = ProductSearchAsyncClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - )) - response = await client.create_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.CreateReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -@pytest.mark.asyncio -async def test_create_reference_image_async_from_dict(): - await test_create_reference_image_async(request_type=dict) - - -def test_create_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.CreateReferenceImageRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - call.return_value = product_search_service.ReferenceImage() - client.create_reference_image(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_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.CreateReferenceImageRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - await client.create_reference_image(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_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_reference_image( - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') - assert args[0].reference_image_id == 'reference_image_id_value' - - -def test_create_reference_image_flattened_error(): - client = ProductSearchClient( - 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_reference_image( - product_search_service.CreateReferenceImageRequest(), - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_value', - ) - - -@pytest.mark.asyncio -async def test_create_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_reference_image( - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_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].reference_image == product_search_service.ReferenceImage(name='name_value') - assert args[0].reference_image_id == 'reference_image_id_value' - - -@pytest.mark.asyncio -async def test_create_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_image( - product_search_service.CreateReferenceImageRequest(), - parent='parent_value', - reference_image=product_search_service.ReferenceImage(name='name_value'), - reference_image_id='reference_image_id_value', - ) - - -def test_delete_reference_image(transport: str = 'grpc', request_type=product_search_service.DeleteReferenceImageRequest): - client = ProductSearchClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_reference_image_from_dict(): - test_delete_reference_image(request_type=dict) - - -def test_delete_reference_image_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 = ProductSearchClient( - 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_reference_image), - '__call__') as call: - client.delete_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_delete_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.DeleteReferenceImageRequest): - client = ProductSearchAsyncClient( - 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_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.DeleteReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_reference_image_async_from_dict(): - await test_delete_reference_image_async(request_type=dict) - - -def test_delete_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.DeleteReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - call.return_value = None - client.delete_reference_image(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_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.DeleteReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_reference_image(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_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_reference_image( - 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_reference_image_flattened_error(): - client = ProductSearchClient( - 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_reference_image( - product_search_service.DeleteReferenceImageRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_reference_image( - 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_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_image( - product_search_service.DeleteReferenceImageRequest(), - name='name_value', - ) - - -def test_list_reference_images(transport: str = 'grpc', request_type=product_search_service.ListReferenceImagesRequest): - client = ProductSearchClient( - 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_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse( - page_size=951, - next_page_token='next_page_token_value', - ) - response = client.list_reference_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReferenceImagesPager) - assert response.page_size == 951 - assert response.next_page_token == 'next_page_token_value' - - -def test_list_reference_images_from_dict(): - test_list_reference_images(request_type=dict) - - -def test_list_reference_images_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 = ProductSearchClient( - 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_reference_images), - '__call__') as call: - client.list_reference_images() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - -@pytest.mark.asyncio -async def test_list_reference_images_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListReferenceImagesRequest): - client = ProductSearchAsyncClient( - 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_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse( - page_size=951, - next_page_token='next_page_token_value', - )) - response = await client.list_reference_images(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListReferenceImagesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListReferenceImagesAsyncPager) - assert response.page_size == 951 - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_reference_images_async_from_dict(): - await test_list_reference_images_async(request_type=dict) - - -def test_list_reference_images_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListReferenceImagesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - call.return_value = product_search_service.ListReferenceImagesResponse() - client.list_reference_images(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_reference_images_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListReferenceImagesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) - await client.list_reference_images(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_reference_images_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_reference_images( - 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_reference_images_flattened_error(): - client = ProductSearchClient( - 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_reference_images( - product_search_service.ListReferenceImagesRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_reference_images_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListReferenceImagesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListReferenceImagesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_reference_images( - 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_reference_images_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_reference_images( - product_search_service.ListReferenceImagesRequest(), - parent='parent_value', - ) - - -def test_list_reference_images_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_reference_images(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.ReferenceImage) - for i in results) - -def test_list_reference_images_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - pages = list(client.list_reference_images(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_reference_images_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_reference_images(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, product_search_service.ReferenceImage) - for i in responses) - -@pytest.mark.asyncio -async def test_list_reference_images_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_reference_images), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - next_page_token='abc', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[], - next_page_token='def', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - ], - next_page_token='ghi', - ), - product_search_service.ListReferenceImagesResponse( - reference_images=[ - product_search_service.ReferenceImage(), - product_search_service.ReferenceImage(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_reference_images(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_get_reference_image(transport: str = 'grpc', request_type=product_search_service.GetReferenceImageRequest): - client = ProductSearchClient( - 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.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - ) - response = client.get_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -def test_get_reference_image_from_dict(): - test_get_reference_image(request_type=dict) - - -def test_get_reference_image_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 = ProductSearchClient( - 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.get_reference_image), - '__call__') as call: - client.get_reference_image() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - -@pytest.mark.asyncio -async def test_get_reference_image_async(transport: str = 'grpc_asyncio', request_type=product_search_service.GetReferenceImageRequest): - client = ProductSearchAsyncClient( - 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.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage( - name='name_value', - uri='uri_value', - )) - response = await client.get_reference_image(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.GetReferenceImageRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, product_search_service.ReferenceImage) - assert response.name == 'name_value' - assert response.uri == 'uri_value' - - -@pytest.mark.asyncio -async def test_get_reference_image_async_from_dict(): - await test_get_reference_image_async(request_type=dict) - - -def test_get_reference_image_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.GetReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - call.return_value = product_search_service.ReferenceImage() - client.get_reference_image(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_get_reference_image_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.GetReferenceImageRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - await client.get_reference_image(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_get_reference_image_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_reference_image( - 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_get_reference_image_flattened_error(): - client = ProductSearchClient( - 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.get_reference_image( - product_search_service.GetReferenceImageRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_get_reference_image_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_reference_image), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ReferenceImage() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ReferenceImage()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_reference_image( - 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_get_reference_image_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.get_reference_image( - product_search_service.GetReferenceImageRequest(), - name='name_value', - ) - - -def test_add_product_to_product_set(transport: str = 'grpc', request_type=product_search_service.AddProductToProductSetRequest): - client = ProductSearchClient( - 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.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.add_product_to_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_add_product_to_product_set_from_dict(): - test_add_product_to_product_set(request_type=dict) - - -def test_add_product_to_product_set_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 = ProductSearchClient( - 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.add_product_to_product_set), - '__call__') as call: - client.add_product_to_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.AddProductToProductSetRequest): - client = ProductSearchAsyncClient( - 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.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.add_product_to_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.AddProductToProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_async_from_dict(): - await test_add_product_to_product_set_async(request_type=dict) - - -def test_add_product_to_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.AddProductToProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - call.return_value = None - client.add_product_to_product_set(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_add_product_to_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.AddProductToProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.add_product_to_product_set(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_add_product_to_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.add_product_to_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -def test_add_product_to_product_set_flattened_error(): - client = ProductSearchClient( - 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.add_product_to_product_set( - product_search_service.AddProductToProductSetRequest(), - name='name_value', - product='product_value', - ) - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_product_to_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.add_product_to_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -@pytest.mark.asyncio -async def test_add_product_to_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.add_product_to_product_set( - product_search_service.AddProductToProductSetRequest(), - name='name_value', - product='product_value', - ) - - -def test_remove_product_from_product_set(transport: str = 'grpc', request_type=product_search_service.RemoveProductFromProductSetRequest): - client = ProductSearchClient( - 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.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.remove_product_from_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_remove_product_from_product_set_from_dict(): - test_remove_product_from_product_set(request_type=dict) - - -def test_remove_product_from_product_set_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 = ProductSearchClient( - 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.remove_product_from_product_set), - '__call__') as call: - client.remove_product_from_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.RemoveProductFromProductSetRequest): - client = ProductSearchAsyncClient( - 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.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.remove_product_from_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.RemoveProductFromProductSetRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_async_from_dict(): - await test_remove_product_from_product_set_async(request_type=dict) - - -def test_remove_product_from_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.RemoveProductFromProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - call.return_value = None - client.remove_product_from_product_set(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_remove_product_from_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.RemoveProductFromProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.remove_product_from_product_set(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_remove_product_from_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.remove_product_from_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -def test_remove_product_from_product_set_flattened_error(): - client = ProductSearchClient( - 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.remove_product_from_product_set( - product_search_service.RemoveProductFromProductSetRequest(), - name='name_value', - product='product_value', - ) - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.remove_product_from_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.remove_product_from_product_set( - name='name_value', - product='product_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' - assert args[0].product == 'product_value' - - -@pytest.mark.asyncio -async def test_remove_product_from_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.remove_product_from_product_set( - product_search_service.RemoveProductFromProductSetRequest(), - name='name_value', - product='product_value', - ) - - -def test_list_products_in_product_set(transport: str = 'grpc', request_type=product_search_service.ListProductsInProductSetRequest): - client = ProductSearchClient( - 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_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products_in_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsInProductSetPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_in_product_set_from_dict(): - test_list_products_in_product_set(request_type=dict) - - -def test_list_products_in_product_set_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 = ProductSearchClient( - 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_products_in_product_set), - '__call__') as call: - client.list_products_in_product_set() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ListProductsInProductSetRequest): - client = ProductSearchAsyncClient( - 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_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products_in_product_set(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ListProductsInProductSetRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsInProductSetAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async_from_dict(): - await test_list_products_in_product_set_async(request_type=dict) - - -def test_list_products_in_product_set_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ListProductsInProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - call.return_value = product_search_service.ListProductsInProductSetResponse() - client.list_products_in_product_set(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_list_products_in_product_set_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ListProductsInProductSetRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) - await client.list_products_in_product_set(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_list_products_in_product_set_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products_in_product_set( - 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_list_products_in_product_set_flattened_error(): - client = ProductSearchClient( - 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_products_in_product_set( - product_search_service.ListProductsInProductSetRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_list_products_in_product_set_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = product_search_service.ListProductsInProductSetResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(product_search_service.ListProductsInProductSetResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products_in_product_set( - 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_list_products_in_product_set_flattened_error_async(): - client = ProductSearchAsyncClient( - 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_products_in_product_set( - product_search_service.ListProductsInProductSetRequest(), - name='name_value', - ) - - -def test_list_products_in_product_set_pager(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('name', ''), - )), - ) - pager = client.list_products_in_product_set(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, product_search_service.Product) - for i in results) - -def test_list_products_in_product_set_pages(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products_in_product_set(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_products_in_product_set_async_pager(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products_in_product_set(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, product_search_service.Product) - for i in responses) - -@pytest.mark.asyncio -async def test_list_products_in_product_set_async_pages(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products_in_product_set), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - product_search_service.Product(), - ], - next_page_token='abc', - ), - product_search_service.ListProductsInProductSetResponse( - products=[], - next_page_token='def', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - ], - next_page_token='ghi', - ), - product_search_service.ListProductsInProductSetResponse( - products=[ - product_search_service.Product(), - product_search_service.Product(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_products_in_product_set(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_import_product_sets(transport: str = 'grpc', request_type=product_search_service.ImportProductSetsRequest): - client = ProductSearchClient( - 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.import_product_sets), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.import_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_import_product_sets_from_dict(): - test_import_product_sets(request_type=dict) - - -def test_import_product_sets_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 = ProductSearchClient( - 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.import_product_sets), - '__call__') as call: - client.import_product_sets() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - -@pytest.mark.asyncio -async def test_import_product_sets_async(transport: str = 'grpc_asyncio', request_type=product_search_service.ImportProductSetsRequest): - client = ProductSearchAsyncClient( - 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.import_product_sets), - '__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.import_product_sets(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.ImportProductSetsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_import_product_sets_async_from_dict(): - await test_import_product_sets_async(request_type=dict) - - -def test_import_product_sets_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.ImportProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.import_product_sets(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_import_product_sets_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.ImportProductSetsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.import_product_sets(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_import_product_sets_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__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.import_product_sets( - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) - - -def test_import_product_sets_flattened_error(): - client = ProductSearchClient( - 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.import_product_sets( - product_search_service.ImportProductSetsRequest(), - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), - ) - - -@pytest.mark.asyncio -async def test_import_product_sets_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.import_product_sets), - '__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.import_product_sets( - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_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].input_config == product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')) - - -@pytest.mark.asyncio -async def test_import_product_sets_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.import_product_sets( - product_search_service.ImportProductSetsRequest(), - parent='parent_value', - input_config=product_search_service.ImportProductSetsInputConfig(gcs_source=product_search_service.ImportProductSetsGcsSource(csv_file_uri='csv_file_uri_value')), - ) - - -def test_purge_products(transport: str = 'grpc', request_type=product_search_service.PurgeProductsRequest): - client = ProductSearchClient( - 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.purge_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.purge_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.PurgeProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_purge_products_from_dict(): - test_purge_products(request_type=dict) - - -def test_purge_products_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 = ProductSearchClient( - 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.purge_products), - '__call__') as call: - client.purge_products() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.PurgeProductsRequest() - - -@pytest.mark.asyncio -async def test_purge_products_async(transport: str = 'grpc_asyncio', request_type=product_search_service.PurgeProductsRequest): - client = ProductSearchAsyncClient( - 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.purge_products), - '__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.purge_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == product_search_service.PurgeProductsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_purge_products_async_from_dict(): - await test_purge_products_async(request_type=dict) - - -def test_purge_products_field_headers(): - client = ProductSearchClient( - 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 = product_search_service.PurgeProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.purge_products(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_purge_products_field_headers_async(): - client = ProductSearchAsyncClient( - 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 = product_search_service.PurgeProductsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.purge_products(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_purge_products_flattened(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__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.purge_products( - 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_purge_products_flattened_error(): - client = ProductSearchClient( - 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.purge_products( - product_search_service.PurgeProductsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_purge_products_flattened_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.purge_products), - '__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.purge_products( - 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_purge_products_flattened_error_async(): - client = ProductSearchAsyncClient( - 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.purge_products( - product_search_service.PurgeProductsRequest(), - parent='parent_value', - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductSearchClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ProductSearchClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductSearchGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ProductSearchGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, -]) -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 = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ProductSearchGrpcTransport, - ) - -def test_product_search_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ProductSearchTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_product_search_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ProductSearchTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'create_product_set', - 'list_product_sets', - 'get_product_set', - 'update_product_set', - 'delete_product_set', - 'create_product', - 'list_products', - 'get_product', - 'update_product', - 'delete_product', - 'create_reference_image', - 'delete_reference_image', - 'list_reference_images', - 'get_reference_image', - 'add_product_to_product_set', - 'remove_product_from_product_set', - 'list_products_in_product_set', - 'import_product_sets', - 'purge_products', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # 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_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - 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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', - ), - quota_project_id="octopus", - ) - - -def test_product_search_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.vision_v1p4beta1.services.product_search.transports.ProductSearchTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductSearchTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_product_search_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) - ProductSearchClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_product_search_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', 'https://www.googleapis.com/auth/cloud-vision',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductSearchGrpcTransport, - transports.ProductSearchGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_product_search_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', - 'https://www.googleapis.com/auth/cloud-vision', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ProductSearchGrpcTransport, grpc_helpers), - (transports.ProductSearchGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_product_search_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( - "vision.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/cloud-vision', -), - scopes=["1", "2"], - default_host="vision.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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_product_search_host_no_port(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com'), - ) - assert client.transport._host == 'vision.googleapis.com:443' - - -def test_product_search_host_with_port(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='vision.googleapis.com:8000'), - ) - assert client.transport._host == 'vision.googleapis.com:8000' - -def test_product_search_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductSearchGrpcTransport( - 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_product_search_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductSearchGrpcAsyncIOTransport( - 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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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.ProductSearchGrpcTransport, transports.ProductSearchGrpcAsyncIOTransport]) -def test_product_search_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_product_search_grpc_lro_client(): - client = ProductSearchClient( - 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_product_search_grpc_lro_async_client(): - client = ProductSearchAsyncClient( - 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_product_path(): - project = "squid" - location = "clam" - product = "whelk" - expected = "projects/{project}/locations/{location}/products/{product}".format(project=project, location=location, product=product, ) - actual = ProductSearchClient.product_path(project, location, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "project": "octopus", - "location": "oyster", - "product": "nudibranch", - } - path = ProductSearchClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_product_path(path) - assert expected == actual - -def test_product_set_path(): - project = "cuttlefish" - location = "mussel" - product_set = "winkle" - expected = "projects/{project}/locations/{location}/productSets/{product_set}".format(project=project, location=location, product_set=product_set, ) - actual = ProductSearchClient.product_set_path(project, location, product_set) - assert expected == actual - - -def test_parse_product_set_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "product_set": "abalone", - } - path = ProductSearchClient.product_set_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_product_set_path(path) - assert expected == actual - -def test_reference_image_path(): - project = "squid" - location = "clam" - product = "whelk" - reference_image = "octopus" - expected = "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}".format(project=project, location=location, product=product, reference_image=reference_image, ) - actual = ProductSearchClient.reference_image_path(project, location, product, reference_image) - assert expected == actual - - -def test_parse_reference_image_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "product": "cuttlefish", - "reference_image": "mussel", - } - path = ProductSearchClient.reference_image_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_reference_image_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ProductSearchClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nautilus", - } - path = ProductSearchClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "scallop" - expected = "folders/{folder}".format(folder=folder, ) - actual = ProductSearchClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "abalone", - } - path = ProductSearchClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "squid" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ProductSearchClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "clam", - } - path = ProductSearchClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "whelk" - expected = "projects/{project}".format(project=project, ) - actual = ProductSearchClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "octopus", - } - path = ProductSearchClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "oyster" - location = "nudibranch" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = ProductSearchClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - } - path = ProductSearchClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ProductSearchClient.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.ProductSearchTransport, '_prep_wrapped_messages') as prep: - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ProductSearchTransport, '_prep_wrapped_messages') as prep: - transport_class = ProductSearchClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = ProductSearchAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - -def test_transport_close(): - transports = { - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'grpc', - ] - for transport in transports: - client = ProductSearchClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() diff --git a/tests/unit/gapic/vision_v1/test_image_annotator.py b/tests/unit/gapic/vision_v1/test_image_annotator.py index e0315a8a..da4a490d 100644 --- a/tests/unit/gapic/vision_v1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1/test_image_annotator.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1.services.image_annotator import ImageAnnotatorAsyncClient @@ -1401,6 +1402,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1959,3 +1963,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1/test_product_search.py b/tests/unit/gapic/vision_v1/test_product_search.py index c2b64a18..35c5b80d 100644 --- a/tests/unit/gapic/vision_v1/test_product_search.py +++ b/tests/unit/gapic/vision_v1/test_product_search.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1.services.product_search import ProductSearchAsyncClient @@ -5533,6 +5534,9 @@ def test_product_search_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -6120,3 +6124,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py index 618d0077..a4c35d71 100644 --- a/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p1beta1/test_image_annotator.py @@ -29,6 +29,7 @@ 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 path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p1beta1.services.image_annotator import ( @@ -785,6 +786,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_image_annotator_base_transport_with_credentials_file(): @@ -1264,3 +1268,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py index f362962a..3dc9c74c 100644 --- a/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p2beta1/test_image_annotator.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p2beta1.services.image_annotator import ( @@ -992,6 +993,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1502,3 +1506,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py index 2a5466e9..8dea7855 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_image_annotator.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p3beta1.services.image_annotator import ( @@ -994,6 +995,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1552,3 +1556,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py index b6595a2f..09a0c8fe 100644 --- a/tests/unit/gapic/vision_v1p3beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p3beta1/test_product_search.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p3beta1.services.product_search import ( @@ -5333,6 +5334,9 @@ def test_product_search_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -5920,3 +5924,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py index 4b8f2214..aab0a04f 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_image_annotator.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p4beta1.services.image_annotator import ( @@ -1404,6 +1405,9 @@ def test_image_annotator_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -1962,3 +1966,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ImageAnnotatorAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ImageAnnotatorClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py index 969b8b08..afc237d2 100644 --- a/tests/unit/gapic/vision_v1p4beta1/test_product_search.py +++ b/tests/unit/gapic/vision_v1p4beta1/test_product_search.py @@ -32,6 +32,7 @@ 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.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.vision_v1p4beta1.services.product_search import ( @@ -5535,6 +5536,9 @@ def test_product_search_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -6122,3 +6126,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ProductSearchAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = ProductSearchClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called()