diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 0ddb512d..c60c5300 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -10,6 +10,5 @@ branchProtectionRules: - 'Kokoro' - 'cla/google' - 'Samples - Lint' - - 'Samples - Python 3.6' - 'Samples - Python 3.7' - 'Samples - Python 3.8' diff --git a/CHANGELOG.md b/CHANGELOG.md index d6fe8a06..46634590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ [1]: https://pypi.org/project/google-cloud-language/#history +## [2.4.0](https://github.com/googleapis/python-language/compare/v2.3.2...v2.4.0) (2022-02-28) + + +### Features + +* add api key support ([#256](https://github.com/googleapis/python-language/issues/256)) ([593ec8a](https://github.com/googleapis/python-language/commit/593ec8a998c612b3a87b4b9a53bd166c0b2c10f6)) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([3e7c964](https://github.com/googleapis/python-language/commit/3e7c96410914d9080ecd0325c61bdc624adf08e1)) + ### [2.3.2](https://github.com/googleapis/python-language/compare/v2.3.1...v2.3.2) (2022-01-20) diff --git a/google/cloud/language/__init__.py b/google/cloud/language/__init__.py index ef7f887d..07624150 100644 --- a/google/cloud/language/__init__.py +++ b/google/cloud/language/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/__init__.py b/google/cloud/language_v1/__init__.py index ad83a6fa..bcca7fb4 100644 --- a/google/cloud/language_v1/__init__.py +++ b/google/cloud/language_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/services/__init__.py b/google/cloud/language_v1/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/language_v1/services/__init__.py +++ b/google/cloud/language_v1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/services/language_service/__init__.py b/google/cloud/language_v1/services/language_service/__init__.py index 46ba988d..d12b0495 100644 --- a/google/cloud/language_v1/services/language_service/__init__.py +++ b/google/cloud/language_v1/services/language_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/services/language_service/async_client.py b/google/cloud/language_v1/services/language_service/async_client.py index 8121cc51..33e58142 100644 --- a/google/cloud/language_v1/services/language_service/async_client.py +++ b/google/cloud/language_v1/services/language_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -105,6 +105,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return LanguageServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> LanguageServiceTransport: """Returns the transport used by the client instance. @@ -177,6 +213,28 @@ async def analyze_sentiment( ) -> language_service.AnalyzeSentimentResponse: r"""Analyzes the sentiment of the provided text. + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_sentiment(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeSentimentRequest, dict]): The request object. The sentiment analysis request @@ -206,7 +264,7 @@ async def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -263,6 +321,29 @@ async def analyze_entities( salience, mentions for each entity, and other properties. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_entities(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = client.analyze_entities(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeEntitiesRequest, dict]): The request object. The entity analysis request message. @@ -289,7 +370,7 @@ async def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -346,6 +427,29 @@ async def analyze_entity_sentiment( in the text and analyzes sentiment associated with each entity and its mentions. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeEntitySentimentRequest, dict]): The request object. The entity-level sentiment analysis @@ -375,7 +479,7 @@ async def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -431,6 +535,29 @@ async def analyze_syntax( boundaries and tokenization along with part of speech tags, dependency trees, and other properties. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_syntax(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = client.analyze_syntax(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeSyntaxRequest, dict]): The request object. The syntax analysis request message. @@ -457,7 +584,7 @@ async def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -510,6 +637,28 @@ async def classify_text( ) -> language_service.ClassifyTextResponse: r"""Classifies a document into categories. + .. code-block:: python + + from google.cloud import language_v1 + + def sample_classify_text(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = client.classify_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.ClassifyTextRequest, dict]): The request object. The document classification request @@ -532,7 +681,7 @@ async def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -587,6 +736,29 @@ async def annotate_text( that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_annotate_text(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = client.annotate_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnnotateTextRequest, dict]): The request object. The request message for the text @@ -622,7 +794,7 @@ async def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/google/cloud/language_v1/services/language_service/client.py b/google/cloud/language_v1/services/language_service/client.py index ea4653b1..0942d7f2 100644 --- a/google/cloud/language_v1/services/language_service/client.py +++ b/google/cloud/language_v1/services/language_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -219,6 +219,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -269,57 +336,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, LanguageServiceTransport): # transport is a LanguageServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -331,6 +363,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -355,6 +396,28 @@ def analyze_sentiment( ) -> language_service.AnalyzeSentimentResponse: r"""Analyzes the sentiment of the provided text. + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_sentiment(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeSentimentRequest, dict]): The request object. The sentiment analysis request @@ -384,7 +447,7 @@ def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -431,6 +494,29 @@ def analyze_entities( salience, mentions for each entity, and other properties. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_entities(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = client.analyze_entities(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeEntitiesRequest, dict]): The request object. The entity analysis request message. @@ -457,7 +543,7 @@ def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -504,6 +590,29 @@ def analyze_entity_sentiment( in the text and analyzes sentiment associated with each entity and its mentions. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeEntitySentimentRequest, dict]): The request object. The entity-level sentiment analysis @@ -533,7 +642,7 @@ def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -579,6 +688,29 @@ def analyze_syntax( boundaries and tokenization along with part of speech tags, dependency trees, and other properties. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_analyze_syntax(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = client.analyze_syntax(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnalyzeSyntaxRequest, dict]): The request object. The syntax analysis request message. @@ -605,7 +737,7 @@ def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -648,6 +780,28 @@ def classify_text( ) -> language_service.ClassifyTextResponse: r"""Classifies a document into categories. + .. code-block:: python + + from google.cloud import language_v1 + + def sample_classify_text(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = client.classify_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.ClassifyTextRequest, dict]): The request object. The document classification request @@ -670,7 +824,7 @@ def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -715,6 +869,29 @@ def annotate_text( that analyzeSentiment, analyzeEntities, and analyzeSyntax provide in one call. + + .. code-block:: python + + from google.cloud import language_v1 + + def sample_annotate_text(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = client.annotate_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1.types.AnnotateTextRequest, dict]): The request object. The request message for the text @@ -750,7 +927,7 @@ def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/google/cloud/language_v1/services/language_service/transports/__init__.py b/google/cloud/language_v1/services/language_service/transports/__init__.py index be3ebc9a..2cb702a6 100644 --- a/google/cloud/language_v1/services/language_service/transports/__init__.py +++ b/google/cloud/language_v1/services/language_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/services/language_service/transports/base.py b/google/cloud/language_v1/services/language_service/transports/base.py index 5d147fc1..b1f97f7a 100644 --- a/google/cloud/language_v1/services/language_service/transports/base.py +++ b/google/cloud/language_v1/services/language_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/services/language_service/transports/grpc.py b/google/cloud/language_v1/services/language_service/transports/grpc.py index 94941e4e..86ea561d 100644 --- a/google/cloud/language_v1/services/language_service/transports/grpc.py +++ b/google/cloud/language_v1/services/language_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -159,8 +159,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py b/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py index 681336e2..4b10a361 100644 --- a/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py +++ b/google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -204,8 +204,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/language_v1/types/__init__.py b/google/cloud/language_v1/types/__init__.py index adb04117..6a80ff72 100644 --- a/google/cloud/language_v1/types/__init__.py +++ b/google/cloud/language_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1/types/language_service.py b/google/cloud/language_v1/types/language_service.py index 25a6fff4..02fec89c 100644 --- a/google/cloud/language_v1/types/language_service.py +++ b/google/cloud/language_v1/types/language_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/__init__.py b/google/cloud/language_v1beta2/__init__.py index ad83a6fa..bcca7fb4 100644 --- a/google/cloud/language_v1beta2/__init__.py +++ b/google/cloud/language_v1beta2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/services/__init__.py b/google/cloud/language_v1beta2/services/__init__.py index 4de65971..e8e1c384 100644 --- a/google/cloud/language_v1beta2/services/__init__.py +++ b/google/cloud/language_v1beta2/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/services/language_service/__init__.py b/google/cloud/language_v1beta2/services/language_service/__init__.py index 46ba988d..d12b0495 100644 --- a/google/cloud/language_v1beta2/services/language_service/__init__.py +++ b/google/cloud/language_v1beta2/services/language_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/services/language_service/async_client.py b/google/cloud/language_v1beta2/services/language_service/async_client.py index 366e2acf..1a212bd5 100644 --- a/google/cloud/language_v1beta2/services/language_service/async_client.py +++ b/google/cloud/language_v1beta2/services/language_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -105,6 +105,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return LanguageServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> LanguageServiceTransport: """Returns the transport used by the client instance. @@ -177,6 +213,28 @@ async def analyze_sentiment( ) -> language_service.AnalyzeSentimentResponse: r"""Analyzes the sentiment of the provided text. + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeSentimentRequest, dict]): The request object. The sentiment analysis request @@ -207,7 +265,7 @@ async def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -264,6 +322,29 @@ async def analyze_entities( salience, mentions for each entity, and other properties. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_entities(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = client.analyze_entities(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeEntitiesRequest, dict]): The request object. The entity analysis request message. @@ -290,7 +371,7 @@ async def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -347,6 +428,29 @@ async def analyze_entity_sentiment( in the text and analyzes sentiment associated with each entity and its mentions. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeEntitySentimentRequest, dict]): The request object. The entity-level sentiment analysis @@ -376,7 +480,7 @@ async def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -432,6 +536,29 @@ async def analyze_syntax( boundaries and tokenization along with part-of-speech tags, dependency trees, and other properties. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_syntax(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = client.analyze_syntax(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeSyntaxRequest, dict]): The request object. The syntax analysis request message. @@ -458,7 +585,7 @@ async def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -511,6 +638,28 @@ async def classify_text( ) -> language_service.ClassifyTextResponse: r"""Classifies a document into categories. + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_classify_text(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = client.classify_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.ClassifyTextRequest, dict]): The request object. The document classification request @@ -533,7 +682,7 @@ async def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -588,6 +737,29 @@ async def annotate_text( sentiment, entity, and classification features in one call. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_annotate_text(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = client.annotate_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnnotateTextRequest, dict]): The request object. The request message for the text @@ -623,7 +795,7 @@ async def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/google/cloud/language_v1beta2/services/language_service/client.py b/google/cloud/language_v1beta2/services/language_service/client.py index 29fd4df7..83cd0992 100644 --- a/google/cloud/language_v1beta2/services/language_service/client.py +++ b/google/cloud/language_v1beta2/services/language_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -219,6 +219,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -269,57 +336,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, LanguageServiceTransport): # transport is a LanguageServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -331,6 +363,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -355,6 +396,28 @@ def analyze_sentiment( ) -> language_service.AnalyzeSentimentResponse: r"""Analyzes the sentiment of the provided text. + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeSentimentRequest, dict]): The request object. The sentiment analysis request @@ -385,7 +448,7 @@ def analyze_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -432,6 +495,29 @@ def analyze_entities( salience, mentions for each entity, and other properties. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_entities(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = client.analyze_entities(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeEntitiesRequest, dict]): The request object. The entity analysis request message. @@ -458,7 +544,7 @@ def analyze_entities( The entity analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -505,6 +591,29 @@ def analyze_entity_sentiment( in the text and analyzes sentiment associated with each entity and its mentions. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeEntitySentimentRequest, dict]): The request object. The entity-level sentiment analysis @@ -534,7 +643,7 @@ def analyze_entity_sentiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -580,6 +689,29 @@ def analyze_syntax( boundaries and tokenization along with part-of-speech tags, dependency trees, and other properties. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_analyze_syntax(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = client.analyze_syntax(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnalyzeSyntaxRequest, dict]): The request object. The syntax analysis request message. @@ -606,7 +738,7 @@ def analyze_syntax( The syntax analysis response message. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, encoding_type]) if request is not None and has_flattened_params: @@ -649,6 +781,28 @@ def classify_text( ) -> language_service.ClassifyTextResponse: r"""Classifies a document into categories. + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_classify_text(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = client.classify_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.ClassifyTextRequest, dict]): The request object. The document classification request @@ -671,7 +825,7 @@ def classify_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document]) if request is not None and has_flattened_params: @@ -716,6 +870,29 @@ def annotate_text( sentiment, entity, and classification features in one call. + + .. code-block:: python + + from google.cloud import language_v1beta2 + + def sample_annotate_text(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = client.annotate_text(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.language_v1beta2.types.AnnotateTextRequest, dict]): The request object. The request message for the text @@ -751,7 +928,7 @@ def annotate_text( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, features, encoding_type]) if request is not None and has_flattened_params: diff --git a/google/cloud/language_v1beta2/services/language_service/transports/__init__.py b/google/cloud/language_v1beta2/services/language_service/transports/__init__.py index be3ebc9a..2cb702a6 100644 --- a/google/cloud/language_v1beta2/services/language_service/transports/__init__.py +++ b/google/cloud/language_v1beta2/services/language_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/services/language_service/transports/base.py b/google/cloud/language_v1beta2/services/language_service/transports/base.py index ea3aba83..cc1fbc12 100644 --- a/google/cloud/language_v1beta2/services/language_service/transports/base.py +++ b/google/cloud/language_v1beta2/services/language_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/services/language_service/transports/grpc.py b/google/cloud/language_v1beta2/services/language_service/transports/grpc.py index 2936db35..c09dea48 100644 --- a/google/cloud/language_v1beta2/services/language_service/transports/grpc.py +++ b/google/cloud/language_v1beta2/services/language_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -159,8 +159,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py b/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py index 5e7e6213..4cb0142e 100644 --- a/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py +++ b/google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -204,8 +204,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/language_v1beta2/types/__init__.py b/google/cloud/language_v1beta2/types/__init__.py index adb04117..6a80ff72 100644 --- a/google/cloud/language_v1beta2/types/__init__.py +++ b/google/cloud/language_v1beta2/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/language_v1beta2/types/language_service.py b/google/cloud/language_v1beta2/types/language_service.py index 68f9297b..3c168b58 100644 --- a/google/cloud/language_v1beta2/types/language_service.py +++ b/google/cloud/language_v1beta2/types/language_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_entities_async.py b/samples/generated_samples/language_v1_generated_language_service_analyze_entities_async.py new file mode 100644 index 00000000..32be0c31 --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_entities_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntities +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeEntities_async] +from google.cloud import language_v1 + + +async def sample_analyze_entities(): + # Create a client + client = language_v1.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = await client.analyze_entities(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeEntities_async] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_entities_sync.py b/samples/generated_samples/language_v1_generated_language_service_analyze_entities_sync.py new file mode 100644 index 00000000..4321949c --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_entities_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntities +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeEntities_sync] +from google.cloud import language_v1 + + +def sample_analyze_entities(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = client.analyze_entities(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeEntities_sync] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_entity_sentiment_async.py b/samples/generated_samples/language_v1_generated_language_service_analyze_entity_sentiment_async.py new file mode 100644 index 00000000..ed70384b --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_entity_sentiment_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntitySentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeEntitySentiment_async] +from google.cloud import language_v1 + + +async def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = await client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeEntitySentiment_async] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_entity_sentiment_sync.py b/samples/generated_samples/language_v1_generated_language_service_analyze_entity_sentiment_sync.py new file mode 100644 index 00000000..59315468 --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_entity_sentiment_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntitySentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeEntitySentiment_sync] +from google.cloud import language_v1 + + +def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeEntitySentiment_sync] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_sentiment_async.py b/samples/generated_samples/language_v1_generated_language_service_analyze_sentiment_async.py new file mode 100644 index 00000000..2391f11c --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_sentiment_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeSentiment_async] +from google.cloud import language_v1 + + +async def sample_analyze_sentiment(): + # Create a client + client = language_v1.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = await client.analyze_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeSentiment_async] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_sentiment_sync.py b/samples/generated_samples/language_v1_generated_language_service_analyze_sentiment_sync.py new file mode 100644 index 00000000..c588371f --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_sentiment_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeSentiment_sync] +from google.cloud import language_v1 + + +def sample_analyze_sentiment(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeSentiment_sync] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_syntax_async.py b/samples/generated_samples/language_v1_generated_language_service_analyze_syntax_async.py new file mode 100644 index 00000000..ea004078 --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_syntax_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSyntax +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeSyntax_async] +from google.cloud import language_v1 + + +async def sample_analyze_syntax(): + # Create a client + client = language_v1.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = await client.analyze_syntax(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeSyntax_async] diff --git a/samples/generated_samples/language_v1_generated_language_service_analyze_syntax_sync.py b/samples/generated_samples/language_v1_generated_language_service_analyze_syntax_sync.py new file mode 100644 index 00000000..01df9c51 --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_analyze_syntax_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSyntax +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnalyzeSyntax_sync] +from google.cloud import language_v1 + + +def sample_analyze_syntax(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = client.analyze_syntax(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnalyzeSyntax_sync] diff --git a/samples/generated_samples/language_v1_generated_language_service_annotate_text_async.py b/samples/generated_samples/language_v1_generated_language_service_annotate_text_async.py new file mode 100644 index 00000000..0edccb1a --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_annotate_text_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnnotateText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnnotateText_async] +from google.cloud import language_v1 + + +async def sample_annotate_text(): + # Create a client + client = language_v1.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = await client.annotate_text(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnnotateText_async] diff --git a/samples/generated_samples/language_v1_generated_language_service_annotate_text_sync.py b/samples/generated_samples/language_v1_generated_language_service_annotate_text_sync.py new file mode 100644 index 00000000..2ccfc4dd --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_annotate_text_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnnotateText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_AnnotateText_sync] +from google.cloud import language_v1 + + +def sample_annotate_text(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = client.annotate_text(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_AnnotateText_sync] diff --git a/samples/generated_samples/language_v1_generated_language_service_classify_text_async.py b/samples/generated_samples/language_v1_generated_language_service_classify_text_async.py new file mode 100644 index 00000000..1ceb7247 --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_classify_text_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ClassifyText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_ClassifyText_async] +from google.cloud import language_v1 + + +async def sample_classify_text(): + # Create a client + client = language_v1.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = await client.classify_text(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_ClassifyText_async] diff --git a/samples/generated_samples/language_v1_generated_language_service_classify_text_sync.py b/samples/generated_samples/language_v1_generated_language_service_classify_text_sync.py new file mode 100644 index 00000000..335d74a1 --- /dev/null +++ b/samples/generated_samples/language_v1_generated_language_service_classify_text_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ClassifyText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1_generated_LanguageService_ClassifyText_sync] +from google.cloud import language_v1 + + +def sample_classify_text(): + # Create a client + client = language_v1.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1.Document() + document.content = "content_value" + + request = language_v1.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = client.classify_text(request=request) + + # Handle the response + print(response) + +# [END language_v1_generated_LanguageService_ClassifyText_sync] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entities_async.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entities_async.py new file mode 100644 index 00000000..f69b7fbd --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entities_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntities +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeEntities_async] +from google.cloud import language_v1beta2 + + +async def sample_analyze_entities(): + # Create a client + client = language_v1beta2.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = await client.analyze_entities(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeEntities_async] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entities_sync.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entities_sync.py new file mode 100644 index 00000000..77dc2c4f --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entities_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntities +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeEntities_sync] +from google.cloud import language_v1beta2 + + +def sample_analyze_entities(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitiesRequest( + document=document, + ) + + # Make the request + response = client.analyze_entities(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeEntities_sync] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entity_sentiment_async.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entity_sentiment_async.py new file mode 100644 index 00000000..ec6b1a8e --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entity_sentiment_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntitySentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeEntitySentiment_async] +from google.cloud import language_v1beta2 + + +async def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = await client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeEntitySentiment_async] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entity_sentiment_sync.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entity_sentiment_sync.py new file mode 100644 index 00000000..74815762 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_entity_sentiment_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeEntitySentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeEntitySentiment_sync] +from google.cloud import language_v1beta2 + + +def sample_analyze_entity_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeEntitySentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_entity_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeEntitySentiment_sync] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_sentiment_async.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_sentiment_async.py new file mode 100644 index 00000000..bea0b0d8 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_sentiment_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeSentiment_async] +from google.cloud import language_v1beta2 + + +async def sample_analyze_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = await client.analyze_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeSentiment_async] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_sentiment_sync.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_sentiment_sync.py new file mode 100644 index 00000000..55031f69 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_sentiment_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSentiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeSentiment_sync] +from google.cloud import language_v1beta2 + + +def sample_analyze_sentiment(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSentimentRequest( + document=document, + ) + + # Make the request + response = client.analyze_sentiment(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeSentiment_sync] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_syntax_async.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_syntax_async.py new file mode 100644 index 00000000..481b9d99 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_syntax_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSyntax +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeSyntax_async] +from google.cloud import language_v1beta2 + + +async def sample_analyze_syntax(): + # Create a client + client = language_v1beta2.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = await client.analyze_syntax(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeSyntax_async] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_analyze_syntax_sync.py b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_syntax_sync.py new file mode 100644 index 00000000..73d34c96 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_analyze_syntax_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnalyzeSyntax +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnalyzeSyntax_sync] +from google.cloud import language_v1beta2 + + +def sample_analyze_syntax(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnalyzeSyntaxRequest( + document=document, + ) + + # Make the request + response = client.analyze_syntax(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnalyzeSyntax_sync] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_annotate_text_async.py b/samples/generated_samples/language_v1beta2_generated_language_service_annotate_text_async.py new file mode 100644 index 00000000..fc3619c5 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_annotate_text_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnnotateText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnnotateText_async] +from google.cloud import language_v1beta2 + + +async def sample_annotate_text(): + # Create a client + client = language_v1beta2.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = await client.annotate_text(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnnotateText_async] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_annotate_text_sync.py b/samples/generated_samples/language_v1beta2_generated_language_service_annotate_text_sync.py new file mode 100644 index 00000000..ac8a7636 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_annotate_text_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AnnotateText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_AnnotateText_sync] +from google.cloud import language_v1beta2 + + +def sample_annotate_text(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.AnnotateTextRequest( + document=document, + ) + + # Make the request + response = client.annotate_text(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_AnnotateText_sync] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_classify_text_async.py b/samples/generated_samples/language_v1beta2_generated_language_service_classify_text_async.py new file mode 100644 index 00000000..72d76f60 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_classify_text_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ClassifyText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_ClassifyText_async] +from google.cloud import language_v1beta2 + + +async def sample_classify_text(): + # Create a client + client = language_v1beta2.LanguageServiceAsyncClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = await client.classify_text(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_ClassifyText_async] diff --git a/samples/generated_samples/language_v1beta2_generated_language_service_classify_text_sync.py b/samples/generated_samples/language_v1beta2_generated_language_service_classify_text_sync.py new file mode 100644 index 00000000..9d000fc2 --- /dev/null +++ b/samples/generated_samples/language_v1beta2_generated_language_service_classify_text_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ClassifyText +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-language + + +# [START language_v1beta2_generated_LanguageService_ClassifyText_sync] +from google.cloud import language_v1beta2 + + +def sample_classify_text(): + # Create a client + client = language_v1beta2.LanguageServiceClient() + + # Initialize request argument(s) + document = language_v1beta2.Document() + document.content = "content_value" + + request = language_v1beta2.ClassifyTextRequest( + document=document, + ) + + # Make the request + response = client.classify_text(request=request) + + # Handle the response + print(response) + +# [END language_v1beta2_generated_LanguageService_ClassifyText_sync] diff --git a/samples/generated_samples/snippet_metadata_language_v1.json b/samples/generated_samples/snippet_metadata_language_v1.json new file mode 100644 index 00000000..ad0df512 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_language_v1.json @@ -0,0 +1,538 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntities" + } + }, + "file": "language_v1_generated_language_service_analyze_entities_async.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeEntities_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntities" + } + }, + "file": "language_v1_generated_language_service_analyze_entities_sync.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeEntities_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntitySentiment" + } + }, + "file": "language_v1_generated_language_service_analyze_entity_sentiment_async.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeEntitySentiment_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntitySentiment" + } + }, + "file": "language_v1_generated_language_service_analyze_entity_sentiment_sync.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeEntitySentiment_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSentiment" + } + }, + "file": "language_v1_generated_language_service_analyze_sentiment_async.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeSentiment_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSentiment" + } + }, + "file": "language_v1_generated_language_service_analyze_sentiment_sync.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeSentiment_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSyntax" + } + }, + "file": "language_v1_generated_language_service_analyze_syntax_async.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeSyntax_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSyntax" + } + }, + "file": "language_v1_generated_language_service_analyze_syntax_sync.py", + "regionTag": "language_v1_generated_LanguageService_AnalyzeSyntax_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnnotateText" + } + }, + "file": "language_v1_generated_language_service_annotate_text_async.py", + "regionTag": "language_v1_generated_LanguageService_AnnotateText_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnnotateText" + } + }, + "file": "language_v1_generated_language_service_annotate_text_sync.py", + "regionTag": "language_v1_generated_LanguageService_AnnotateText_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "ClassifyText" + } + }, + "file": "language_v1_generated_language_service_classify_text_async.py", + "regionTag": "language_v1_generated_LanguageService_ClassifyText_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "ClassifyText" + } + }, + "file": "language_v1_generated_language_service_classify_text_sync.py", + "regionTag": "language_v1_generated_LanguageService_ClassifyText_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_language_v1beta2.json b/samples/generated_samples/snippet_metadata_language_v1beta2.json new file mode 100644 index 00000000..68415e8e --- /dev/null +++ b/samples/generated_samples/snippet_metadata_language_v1beta2.json @@ -0,0 +1,538 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntities" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_entities_async.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeEntities_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntities" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_entities_sync.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeEntities_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntitySentiment" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_entity_sentiment_async.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeEntitySentiment_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeEntitySentiment" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_entity_sentiment_sync.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeEntitySentiment_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSentiment" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_sentiment_async.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeSentiment_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSentiment" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_sentiment_sync.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeSentiment_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSyntax" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_syntax_async.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeSyntax_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnalyzeSyntax" + } + }, + "file": "language_v1beta2_generated_language_service_analyze_syntax_sync.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnalyzeSyntax_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnnotateText" + } + }, + "file": "language_v1beta2_generated_language_service_annotate_text_async.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnnotateText_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "AnnotateText" + } + }, + "file": "language_v1beta2_generated_language_service_annotate_text_sync.py", + "regionTag": "language_v1beta2_generated_LanguageService_AnnotateText_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "ClassifyText" + } + }, + "file": "language_v1beta2_generated_language_service_classify_text_async.py", + "regionTag": "language_v1beta2_generated_LanguageService_ClassifyText_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "LanguageService" + }, + "shortName": "ClassifyText" + } + }, + "file": "language_v1beta2_generated_language_service_classify_text_sync.py", + "regionTag": "language_v1beta2_generated_LanguageService_ClassifyText_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/snippets/api/requirements-test.txt b/samples/snippets/api/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/api/requirements-test.txt +++ b/samples/snippets/api/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/api/requirements.txt b/samples/snippets/api/requirements.txt index c86677b3..16bc690d 100644 --- a/samples/snippets/api/requirements.txt +++ b/samples/snippets/api/requirements.txt @@ -1,3 +1,3 @@ -google-api-python-client==2.36.0 -google-auth==2.3.3 +google-api-python-client==2.38.0 +google-auth==2.6.0 google-auth-httplib2==0.1.0 diff --git a/samples/snippets/classify_text/requirements-test.txt b/samples/snippets/classify_text/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/classify_text/requirements-test.txt +++ b/samples/snippets/classify_text/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/classify_text/requirements.txt b/samples/snippets/classify_text/requirements.txt index 8ebc429c..33cadea4 100644 --- a/samples/snippets/classify_text/requirements.txt +++ b/samples/snippets/classify_text/requirements.txt @@ -1,4 +1,3 @@ -google-cloud-language==2.3.1 -numpy==1.22.1; python_version > '3.7' +google-cloud-language==2.3.2 +numpy==1.22.2; python_version > '3.7' numpy==1.21.4; python_version == '3.7' -numpy==1.19.5; python_version <= '3.6' diff --git a/samples/snippets/cloud-client/v1/requirements-test.txt b/samples/snippets/cloud-client/v1/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/cloud-client/v1/requirements-test.txt +++ b/samples/snippets/cloud-client/v1/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/cloud-client/v1/requirements.txt b/samples/snippets/cloud-client/v1/requirements.txt index d2b8f2f0..8d0fae86 100644 --- a/samples/snippets/cloud-client/v1/requirements.txt +++ b/samples/snippets/cloud-client/v1/requirements.txt @@ -1 +1 @@ -google-cloud-language==2.3.1 +google-cloud-language==2.3.2 diff --git a/samples/snippets/generated-samples/v1/requirements-test.txt b/samples/snippets/generated-samples/v1/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/generated-samples/v1/requirements-test.txt +++ b/samples/snippets/generated-samples/v1/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/generated-samples/v1/requirements.txt b/samples/snippets/generated-samples/v1/requirements.txt index d2b8f2f0..8d0fae86 100644 --- a/samples/snippets/generated-samples/v1/requirements.txt +++ b/samples/snippets/generated-samples/v1/requirements.txt @@ -1 +1 @@ -google-cloud-language==2.3.1 +google-cloud-language==2.3.2 diff --git a/samples/snippets/sentiment/requirements-test.txt b/samples/snippets/sentiment/requirements-test.txt index 92709451..c2845bff 100644 --- a/samples/snippets/sentiment/requirements-test.txt +++ b/samples/snippets/sentiment/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/sentiment/requirements.txt b/samples/snippets/sentiment/requirements.txt index d2b8f2f0..8d0fae86 100644 --- a/samples/snippets/sentiment/requirements.txt +++ b/samples/snippets/sentiment/requirements.txt @@ -1 +1 @@ -google-cloud-language==2.3.1 +google-cloud-language==2.3.2 diff --git a/scripts/fixup_language_v1_keywords.py b/scripts/fixup_language_v1_keywords.py index aac999b1..e4268c0f 100644 --- a/scripts/fixup_language_v1_keywords.py +++ b/scripts/fixup_language_v1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_language_v1beta2_keywords.py b/scripts/fixup_language_v1beta2_keywords.py index aac999b1..e4268c0f 100644 --- a/scripts/fixup_language_v1beta2_keywords.py +++ b/scripts/fixup_language_v1beta2_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index cd04169e..443d0541 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-language" description = "Google Cloud Natural Language API client library" -version = "2.3.2" +version = "2.4.0" # Should be one of: # 'Development Status :: 3 - Alpha' # 'Development Status :: 4 - Beta' @@ -78,6 +78,8 @@ "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Operating System :: OS Independent", "Topic :: Internet", ], diff --git a/tests/__init__.py b/tests/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/language_v1/__init__.py b/tests/unit/gapic/language_v1/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/language_v1/__init__.py +++ b/tests/unit/gapic/language_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/language_v1/test_language_service.py b/tests/unit/gapic/language_v1/test_language_service.py index 3304ab5e..859fa443 100644 --- a/tests/unit/gapic/language_v1/test_language_service.py +++ b/tests/unit/gapic/language_v1/test_language_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -406,6 +406,87 @@ def test_language_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [LanguageServiceClient, LanguageServiceAsyncClient] +) +@mock.patch.object( + LanguageServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(LanguageServiceClient), +) +@mock.patch.object( + LanguageServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(LanguageServiceAsyncClient), +) +def test_language_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + 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=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -438,21 +519,28 @@ def test_language_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (LanguageServiceClient, transports.LanguageServiceGrpcTransport, "grpc"), + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( LanguageServiceAsyncClient, transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_language_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # 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, transport=transport_name) @@ -488,6 +576,75 @@ def test_language_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + LanguageServiceAsyncClient, + transports.LanguageServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_language_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # 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, transport=transport_name) + 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, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "language.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-language", + "https://www.googleapis.com/auth/cloud-platform", + ), + scopes=None, + default_host="language.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [language_service.AnalyzeSentimentRequest, dict,] ) @@ -1601,6 +1758,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.LanguageServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = LanguageServiceClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = LanguageServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.LanguageServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2153,3 +2327,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (LanguageServiceClient, transports.LanguageServiceGrpcTransport), + (LanguageServiceAsyncClient, transports.LanguageServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + 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=mock_cred, + 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, + ) diff --git a/tests/unit/gapic/language_v1beta2/__init__.py b/tests/unit/gapic/language_v1beta2/__init__.py index 4de65971..e8e1c384 100644 --- a/tests/unit/gapic/language_v1beta2/__init__.py +++ b/tests/unit/gapic/language_v1beta2/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/language_v1beta2/test_language_service.py b/tests/unit/gapic/language_v1beta2/test_language_service.py index b12fd591..681ab4b3 100644 --- a/tests/unit/gapic/language_v1beta2/test_language_service.py +++ b/tests/unit/gapic/language_v1beta2/test_language_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -408,6 +408,87 @@ def test_language_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [LanguageServiceClient, LanguageServiceAsyncClient] +) +@mock.patch.object( + LanguageServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(LanguageServiceClient), +) +@mock.patch.object( + LanguageServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(LanguageServiceAsyncClient), +) +def test_language_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + 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=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -440,21 +521,28 @@ def test_language_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (LanguageServiceClient, transports.LanguageServiceGrpcTransport, "grpc"), + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( LanguageServiceAsyncClient, transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_language_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # 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, transport=transport_name) @@ -490,6 +578,75 @@ def test_language_service_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + LanguageServiceClient, + transports.LanguageServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + LanguageServiceAsyncClient, + transports.LanguageServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_language_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # 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, transport=transport_name) + 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, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "language.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-language", + "https://www.googleapis.com/auth/cloud-platform", + ), + scopes=None, + default_host="language.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [language_service.AnalyzeSentimentRequest, dict,] ) @@ -1603,6 +1760,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.LanguageServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = LanguageServiceClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = LanguageServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.LanguageServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2155,3 +2329,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (LanguageServiceClient, transports.LanguageServiceGrpcTransport), + (LanguageServiceAsyncClient, transports.LanguageServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + 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=mock_cred, + 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, + )