Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit b4700a6

Browse files
feat: add common resource helpers; expose transport; remove gRPC send/recv limits (#100)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * feat: Add Java microgen rules to imports Source-Author: Mira Leung <miraleung@users.noreply.github.com> Source-Date: Mon Sep 21 18:04:02 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: aaac658367398e478d650768344b88acebad50d9 Source-Link: googleapis/googleapis@aaac658 * Update gapic-generator-python pin to 0.33.4 PiperOrigin-RevId: 333159182 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Sep 22 14:22:59 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 3dbeac0d54125b123c8dfd39c774b37473c36944 Source-Link: googleapis/googleapis@3dbeac0 * fix: naming style updates Source-Author: Mira Leung <miraleung@google.com> Source-Date: Wed Sep 23 16:33:18 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 3737889dafd012d7f7f724fa04390d42db496e6c Source-Link: googleapis/googleapis@3737889 * Add Service Direcotry v1 protos and configs PiperOrigin-RevId: 333502684 Source-Author: Google APIs <noreply@google.com> Source-Date: Thu Sep 24 06:33:53 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: d3697d47929f34c43bcc4de16c7c761a80e97cf1 Source-Link: googleapis/googleapis@d3697d4 * chore: upgrade to gapic-generator-python 0.35.6 PiperOrigin-RevId: 338157137 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Oct 20 16:08:47 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: c7331b75b0b7bbd614373b7d37085db1c80dd4be Source-Link: googleapis/googleapis@c7331b7 * feat: Add Visual Inspection V1Beta1 API. PiperOrigin-RevId: 338201056 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Oct 20 22:16:12 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 11fd1fb53d03cf4852d3f63d679292e3c7b6e7c8 Source-Link: googleapis/googleapis@11fd1fb * chore: upgrade to gapic-generator-python 0.35.6 PiperOrigin-RevId: 338489505 Source-Author: Google APIs <noreply@google.com> Source-Date: Thu Oct 22 09:36:18 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 4b34a0869404af9d83ae89952d28712a4d29eba6 Source-Link: googleapis/googleapis@4b34a08 * fix: switch firestore/v1 to grpc_service_config PiperOrigin-RevId: 338520351 Source-Author: Google APIs <noreply@google.com> Source-Date: Thu Oct 22 12:01:06 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: b448d7dce89eebc3a4066a9e979a0b96bdb66b62 Source-Link: googleapis/googleapis@b448d7d * build(node): provide hint to npm PiperOrigin-RevId: 339261149 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Oct 27 09:09:14 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: c9d7721bd4e22b3a25d914248fac126a5a91d3d9 Source-Link: googleapis/googleapis@c9d7721 * chore: upgrade to gapic-generator 0.35.9 PiperOrigin-RevId: 339292950 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Oct 27 11:32:46 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 07d41a7e5cade45aba6f0d277c89722b48f2c956 Source-Link: googleapis/googleapis@07d41a7 * chore: migrate firestore/admin to the Java microgenerator Committer: @miraleung PiperOrigin-RevId: 346387604 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Dec 8 12:41:11 2020 -0800 Source-Repo: googleapis/googleapis Source-Sha: 36e1a9a8e31eef72033033aa910be56a64a1793f Source-Link: googleapis/googleapis@36e1a9a * fix: remove client recv msg limit fix: add enums to `types/__init__.py` PiperOrigin-RevId: 347055288 Source-Author: Google APIs <noreply@google.com> Source-Date: Fri Dec 11 12:44:37 2020 -0800 Source-Repo: googleapis/googleapis Source-Sha: dd372aa22ded7a8ba6f0e03a80e06358a3fa0907 Source-Link: googleapis/googleapis@dd372aa
1 parent 2cdb974 commit b4700a6

File tree

22 files changed

+763
-135
lines changed

22 files changed

+763
-135
lines changed

docs/speech_v1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Speech v1 API
33

44
.. automodule:: google.cloud.speech_v1.types
55
:members:
6+
:show-inheritance:

docs/speech_v1p1beta1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Speech v1p1beta1 API
33

44
.. automodule:: google.cloud.speech_v1p1beta1.types
55
:members:
6+
:show-inheritance:

google/cloud/speech_v1/services/speech/async_client.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
1818
from collections import OrderedDict
1919
import functools
2020
import re
21-
from typing import Dict, AsyncIterable, AsyncIterator, Sequence, Tuple, Type, Union
21+
from typing import (
22+
Dict,
23+
AsyncIterable,
24+
Awaitable,
25+
AsyncIterator,
26+
Sequence,
27+
Tuple,
28+
Type,
29+
Union,
30+
)
2231
import pkg_resources
2332

2433
import google.api_core.client_options as ClientOptions # type: ignore
@@ -46,9 +55,37 @@ class SpeechAsyncClient:
4655
DEFAULT_ENDPOINT = SpeechClient.DEFAULT_ENDPOINT
4756
DEFAULT_MTLS_ENDPOINT = SpeechClient.DEFAULT_MTLS_ENDPOINT
4857

58+
common_billing_account_path = staticmethod(SpeechClient.common_billing_account_path)
59+
parse_common_billing_account_path = staticmethod(
60+
SpeechClient.parse_common_billing_account_path
61+
)
62+
63+
common_folder_path = staticmethod(SpeechClient.common_folder_path)
64+
parse_common_folder_path = staticmethod(SpeechClient.parse_common_folder_path)
65+
66+
common_organization_path = staticmethod(SpeechClient.common_organization_path)
67+
parse_common_organization_path = staticmethod(
68+
SpeechClient.parse_common_organization_path
69+
)
70+
71+
common_project_path = staticmethod(SpeechClient.common_project_path)
72+
parse_common_project_path = staticmethod(SpeechClient.parse_common_project_path)
73+
74+
common_location_path = staticmethod(SpeechClient.common_location_path)
75+
parse_common_location_path = staticmethod(SpeechClient.parse_common_location_path)
76+
4977
from_service_account_file = SpeechClient.from_service_account_file
5078
from_service_account_json = from_service_account_file
5179

80+
@property
81+
def transport(self) -> SpeechTransport:
82+
"""Return the transport used by the client instance.
83+
84+
Returns:
85+
SpeechTransport: The transport used by the client instance.
86+
"""
87+
return self._client.transport
88+
5289
get_transport_class = functools.partial(
5390
type(SpeechClient).get_transport_class, type(SpeechClient)
5491
)
@@ -148,7 +185,8 @@ async def recognize(
148185
# Create or coerce a protobuf request object.
149186
# Sanity check: If we got a request object, we should *not* have
150187
# gotten any keyword arguments that map to the request.
151-
if request is not None and any([config, audio]):
188+
has_flattened_params = any([config, audio])
189+
if request is not None and has_flattened_params:
152190
raise ValueError(
153191
"If the `request` argument is set, then none of "
154192
"the individual field arguments should be set."
@@ -245,7 +283,8 @@ async def long_running_recognize(
245283
# Create or coerce a protobuf request object.
246284
# Sanity check: If we got a request object, we should *not* have
247285
# gotten any keyword arguments that map to the request.
248-
if request is not None and any([config, audio]):
286+
has_flattened_params = any([config, audio])
287+
if request is not None and has_flattened_params:
249288
raise ValueError(
250289
"If the `request` argument is set, then none of "
251290
"the individual field arguments should be set."
@@ -290,7 +329,7 @@ def streaming_recognize(
290329
retry: retries.Retry = gapic_v1.method.DEFAULT,
291330
timeout: float = None,
292331
metadata: Sequence[Tuple[str, str]] = (),
293-
) -> AsyncIterable[cloud_speech.StreamingRecognizeResponse]:
332+
) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]:
294333
r"""Performs bidirectional streaming speech recognition:
295334
receive results while sending audio. This method is only
296335
available via the gRPC API (not REST).

google/cloud/speech_v1/services/speech/client.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,74 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
140140

141141
from_service_account_json = from_service_account_file
142142

143+
@property
144+
def transport(self) -> SpeechTransport:
145+
"""Return the transport used by the client instance.
146+
147+
Returns:
148+
SpeechTransport: The transport used by the client instance.
149+
"""
150+
return self._transport
151+
152+
@staticmethod
153+
def common_billing_account_path(billing_account: str,) -> str:
154+
"""Return a fully-qualified billing_account string."""
155+
return "billingAccounts/{billing_account}".format(
156+
billing_account=billing_account,
157+
)
158+
159+
@staticmethod
160+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
161+
"""Parse a billing_account path into its component segments."""
162+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
163+
return m.groupdict() if m else {}
164+
165+
@staticmethod
166+
def common_folder_path(folder: str,) -> str:
167+
"""Return a fully-qualified folder string."""
168+
return "folders/{folder}".format(folder=folder,)
169+
170+
@staticmethod
171+
def parse_common_folder_path(path: str) -> Dict[str, str]:
172+
"""Parse a folder path into its component segments."""
173+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
174+
return m.groupdict() if m else {}
175+
176+
@staticmethod
177+
def common_organization_path(organization: str,) -> str:
178+
"""Return a fully-qualified organization string."""
179+
return "organizations/{organization}".format(organization=organization,)
180+
181+
@staticmethod
182+
def parse_common_organization_path(path: str) -> Dict[str, str]:
183+
"""Parse a organization path into its component segments."""
184+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
185+
return m.groupdict() if m else {}
186+
187+
@staticmethod
188+
def common_project_path(project: str,) -> str:
189+
"""Return a fully-qualified project string."""
190+
return "projects/{project}".format(project=project,)
191+
192+
@staticmethod
193+
def parse_common_project_path(path: str) -> Dict[str, str]:
194+
"""Parse a project path into its component segments."""
195+
m = re.match(r"^projects/(?P<project>.+?)$", path)
196+
return m.groupdict() if m else {}
197+
198+
@staticmethod
199+
def common_location_path(project: str, location: str,) -> str:
200+
"""Return a fully-qualified location string."""
201+
return "projects/{project}/locations/{location}".format(
202+
project=project, location=location,
203+
)
204+
205+
@staticmethod
206+
def parse_common_location_path(path: str) -> Dict[str, str]:
207+
"""Parse a location path into its component segments."""
208+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
209+
return m.groupdict() if m else {}
210+
143211
def __init__(
144212
self,
145213
*,
@@ -175,10 +243,10 @@ def __init__(
175243
not provided, the default SSL client certificate will be used if
176244
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
177245
set, no client certificate will be used.
178-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
179-
The client info used to send a user-agent string along with
180-
API requests. If ``None``, then default info will be used.
181-
Generally, you only need to set this if you're developing
246+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
247+
The client info used to send a user-agent string along with
248+
API requests. If ``None``, then default info will be used.
249+
Generally, you only need to set this if you're developing
182250
your own client library.
183251
184252
Raises:

google/cloud/speech_v1/services/speech/transports/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
_transport_registry["grpc"] = SpeechGrpcTransport
2929
_transport_registry["grpc_asyncio"] = SpeechGrpcAsyncIOTransport
3030

31-
3231
__all__ = (
3332
"SpeechTransport",
3433
"SpeechGrpcTransport",

google/cloud/speech_v1/services/speech/transports/grpc.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ def __init__(
9191
for grpc channel. It is ignored if ``channel`` is provided.
9292
quota_project_id (Optional[str]): An optional project to use for billing
9393
and quota.
94-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
95-
The client info used to send a user-agent string along with
96-
API requests. If ``None``, then default info will be used.
97-
Generally, you only need to set this if you're developing
94+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
95+
The client info used to send a user-agent string along with
96+
API requests. If ``None``, then default info will be used.
97+
Generally, you only need to set this if you're developing
9898
your own client library.
9999
100100
Raises:
@@ -103,13 +103,16 @@ def __init__(
103103
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
104104
and ``credentials_file`` are passed.
105105
"""
106+
self._ssl_channel_credentials = ssl_channel_credentials
107+
106108
if channel:
107109
# Sanity check: Ensure that channel and credentials are not both
108110
# provided.
109111
credentials = False
110112

111113
# If a channel was explicitly provided, set it.
112114
self._grpc_channel = channel
115+
self._ssl_channel_credentials = None
113116
elif api_mtls_endpoint:
114117
warnings.warn(
115118
"api_mtls_endpoint and client_cert_source are deprecated",
@@ -145,7 +148,12 @@ def __init__(
145148
ssl_credentials=ssl_credentials,
146149
scopes=scopes or self.AUTH_SCOPES,
147150
quota_project_id=quota_project_id,
151+
options=[
152+
("grpc.max_send_message_length", -1),
153+
("grpc.max_receive_message_length", -1),
154+
],
148155
)
156+
self._ssl_channel_credentials = ssl_credentials
149157
else:
150158
host = host if ":" in host else host + ":443"
151159

@@ -162,9 +170,14 @@ def __init__(
162170
ssl_credentials=ssl_channel_credentials,
163171
scopes=scopes or self.AUTH_SCOPES,
164172
quota_project_id=quota_project_id,
173+
options=[
174+
("grpc.max_send_message_length", -1),
175+
("grpc.max_receive_message_length", -1),
176+
],
165177
)
166178

167179
self._stubs = {} # type: Dict[str, Callable]
180+
self._operations_client = None
168181

169182
# Run the base constructor.
170183
super().__init__(
@@ -188,7 +201,7 @@ def create_channel(
188201
) -> grpc.Channel:
189202
"""Create and return a gRPC channel object.
190203
Args:
191-
address (Optionsl[str]): The host for the channel to use.
204+
address (Optional[str]): The host for the channel to use.
192205
credentials (Optional[~.Credentials]): The
193206
authorization credentials to attach to requests. These
194207
credentials identify this application to the service. If
@@ -223,12 +236,8 @@ def create_channel(
223236

224237
@property
225238
def grpc_channel(self) -> grpc.Channel:
226-
"""Create the channel designed to connect to this service.
227-
228-
This property caches on the instance; repeated calls return
229-
the same channel.
239+
"""Return the channel designed to connect to this service.
230240
"""
231-
# Return the channel from cache.
232241
return self._grpc_channel
233242

234243
@property
@@ -239,13 +248,11 @@ def operations_client(self) -> operations_v1.OperationsClient:
239248
client.
240249
"""
241250
# Sanity check: Only create a new client if we do not already have one.
242-
if "operations_client" not in self.__dict__:
243-
self.__dict__["operations_client"] = operations_v1.OperationsClient(
244-
self.grpc_channel
245-
)
251+
if self._operations_client is None:
252+
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)
246253

247254
# Return the client from cache.
248-
return self.__dict__["operations_client"]
255+
return self._operations_client
249256

250257
@property
251258
def recognize(

google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,16 @@ def __init__(
148148
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
149149
and ``credentials_file`` are passed.
150150
"""
151+
self._ssl_channel_credentials = ssl_channel_credentials
152+
151153
if channel:
152154
# Sanity check: Ensure that channel and credentials are not both
153155
# provided.
154156
credentials = False
155157

156158
# If a channel was explicitly provided, set it.
157159
self._grpc_channel = channel
160+
self._ssl_channel_credentials = None
158161
elif api_mtls_endpoint:
159162
warnings.warn(
160163
"api_mtls_endpoint and client_cert_source are deprecated",
@@ -190,7 +193,12 @@ def __init__(
190193
ssl_credentials=ssl_credentials,
191194
scopes=scopes or self.AUTH_SCOPES,
192195
quota_project_id=quota_project_id,
196+
options=[
197+
("grpc.max_send_message_length", -1),
198+
("grpc.max_receive_message_length", -1),
199+
],
193200
)
201+
self._ssl_channel_credentials = ssl_credentials
194202
else:
195203
host = host if ":" in host else host + ":443"
196204

@@ -207,6 +215,10 @@ def __init__(
207215
ssl_credentials=ssl_channel_credentials,
208216
scopes=scopes or self.AUTH_SCOPES,
209217
quota_project_id=quota_project_id,
218+
options=[
219+
("grpc.max_send_message_length", -1),
220+
("grpc.max_receive_message_length", -1),
221+
],
210222
)
211223

212224
# Run the base constructor.
@@ -220,6 +232,7 @@ def __init__(
220232
)
221233

222234
self._stubs = {}
235+
self._operations_client = None
223236

224237
@property
225238
def grpc_channel(self) -> aio.Channel:
@@ -239,13 +252,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient:
239252
client.
240253
"""
241254
# Sanity check: Only create a new client if we do not already have one.
242-
if "operations_client" not in self.__dict__:
243-
self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient(
255+
if self._operations_client is None:
256+
self._operations_client = operations_v1.OperationsAsyncClient(
244257
self.grpc_channel
245258
)
246259

247260
# Return the client from cache.
248-
return self.__dict__["operations_client"]
261+
return self._operations_client
249262

250263
@property
251264
def recognize(

google/cloud/speech_v1/types/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
WordInfo,
3636
)
3737

38-
3938
__all__ = (
4039
"RecognizeRequest",
4140
"LongRunningRecognizeRequest",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy