Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit cff1cd1

Browse files
chore: upgrade gapic-generator-python to 0.43.1 (#108)
PiperOrigin-RevId: 364411656 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 22 14:40:22 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 149a3a84c29c9b8189576c7442ccb6dcf6a8f95b Source-Link: googleapis/googleapis@149a3a8
1 parent 6aec46e commit cff1cd1

File tree

8 files changed

+292
-286
lines changed

8 files changed

+292
-286
lines changed

google/cloud/texttospeech_v1/services/text_to_speech/async_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ async def list_voices(
233233
predicate=retries.if_exception_type(
234234
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
235235
),
236+
deadline=600.0,
236237
),
237238
default_timeout=600.0,
238239
client_info=DEFAULT_CLIENT_INFO,
@@ -329,6 +330,7 @@ async def synthesize_speech(
329330
predicate=retries.if_exception_type(
330331
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
331332
),
333+
deadline=600.0,
332334
),
333335
default_timeout=600.0,
334336
client_info=DEFAULT_CLIENT_INFO,

google/cloud/texttospeech_v1/services/text_to_speech/transports/base.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,20 @@ def __init__(
6969
scope (Optional[Sequence[str]]): A list of scopes.
7070
quota_project_id (Optional[str]): An optional project to use for billing
7171
and quota.
72-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
73-
The client info used to send a user-agent string along with
74-
API requests. If ``None``, then default info will be used.
75-
Generally, you only need to set this if you're developing
72+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
73+
The client info used to send a user-agent string along with
74+
API requests. If ``None``, then default info will be used.
75+
Generally, you only need to set this if you're developing
7676
your own client library.
7777
"""
7878
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
7979
if ":" not in host:
8080
host += ":443"
8181
self._host = host
8282

83+
# Save the scopes.
84+
self._scopes = scopes or self.AUTH_SCOPES
85+
8386
# If no credentials are provided, then determine the appropriate
8487
# defaults.
8588
if credentials and credentials_file:
@@ -89,20 +92,17 @@ def __init__(
8992

9093
if credentials_file is not None:
9194
credentials, _ = auth.load_credentials_from_file(
92-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
95+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
9396
)
9497

9598
elif credentials is None:
9699
credentials, _ = auth.default(
97-
scopes=scopes, quota_project_id=quota_project_id
100+
scopes=self._scopes, quota_project_id=quota_project_id
98101
)
99102

100103
# Save the credentials.
101104
self._credentials = credentials
102105

103-
# Lifted into its own function so it can be stubbed out during tests.
104-
self._prep_wrapped_messages(client_info)
105-
106106
def _prep_wrapped_messages(self, client_info):
107107
# Precompute the wrapped methods.
108108
self._wrapped_methods = {
@@ -115,6 +115,7 @@ def _prep_wrapped_messages(self, client_info):
115115
predicate=retries.if_exception_type(
116116
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
117117
),
118+
deadline=600.0,
118119
),
119120
default_timeout=600.0,
120121
client_info=client_info,
@@ -128,6 +129,7 @@ def _prep_wrapped_messages(self, client_info):
128129
predicate=retries.if_exception_type(
129130
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
130131
),
132+
deadline=600.0,
131133
),
132134
default_timeout=600.0,
133135
client_info=client_info,

google/cloud/texttospeech_v1/services/text_to_speech/transports/grpc.py

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -106,96 +106,69 @@ def __init__(
106106
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
107107
and ``credentials_file`` are passed.
108108
"""
109+
self._grpc_channel = None
109110
self._ssl_channel_credentials = ssl_channel_credentials
111+
self._stubs: Dict[str, Callable] = {}
110112

111113
if api_mtls_endpoint:
112114
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
113115
if client_cert_source:
114116
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
115117

116118
if channel:
117-
# Sanity check: Ensure that channel and credentials are not both
118-
# provided.
119+
# Ignore credentials if a channel was passed.
119120
credentials = False
120-
121121
# If a channel was explicitly provided, set it.
122122
self._grpc_channel = channel
123123
self._ssl_channel_credentials = None
124-
elif api_mtls_endpoint:
125-
host = (
126-
api_mtls_endpoint
127-
if ":" in api_mtls_endpoint
128-
else api_mtls_endpoint + ":443"
129-
)
130-
131-
if credentials is None:
132-
credentials, _ = auth.default(
133-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
134-
)
135-
136-
# Create SSL credentials with client_cert_source or application
137-
# default SSL credentials.
138-
if client_cert_source:
139-
cert, key = client_cert_source()
140-
ssl_credentials = grpc.ssl_channel_credentials(
141-
certificate_chain=cert, private_key=key
142-
)
143-
else:
144-
ssl_credentials = SslCredentials().ssl_credentials
145124

146-
# create a new channel. The provided one is ignored.
147-
self._grpc_channel = type(self).create_channel(
148-
host,
149-
credentials=credentials,
150-
credentials_file=credentials_file,
151-
ssl_credentials=ssl_credentials,
152-
scopes=scopes or self.AUTH_SCOPES,
153-
quota_project_id=quota_project_id,
154-
options=[
155-
("grpc.max_send_message_length", -1),
156-
("grpc.max_receive_message_length", -1),
157-
],
158-
)
159-
self._ssl_channel_credentials = ssl_credentials
160125
else:
161-
host = host if ":" in host else host + ":443"
126+
if api_mtls_endpoint:
127+
host = api_mtls_endpoint
128+
129+
# Create SSL credentials with client_cert_source or application
130+
# default SSL credentials.
131+
if client_cert_source:
132+
cert, key = client_cert_source()
133+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
134+
certificate_chain=cert, private_key=key
135+
)
136+
else:
137+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
162138

163-
if credentials is None:
164-
credentials, _ = auth.default(
165-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
166-
)
139+
else:
140+
if client_cert_source_for_mtls and not ssl_channel_credentials:
141+
cert, key = client_cert_source_for_mtls()
142+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
143+
certificate_chain=cert, private_key=key
144+
)
167145

168-
if client_cert_source_for_mtls and not ssl_channel_credentials:
169-
cert, key = client_cert_source_for_mtls()
170-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
171-
certificate_chain=cert, private_key=key
172-
)
146+
# The base transport sets the host, credentials and scopes
147+
super().__init__(
148+
host=host,
149+
credentials=credentials,
150+
credentials_file=credentials_file,
151+
scopes=scopes,
152+
quota_project_id=quota_project_id,
153+
client_info=client_info,
154+
)
173155

174-
# create a new channel. The provided one is ignored.
156+
if not self._grpc_channel:
175157
self._grpc_channel = type(self).create_channel(
176-
host,
177-
credentials=credentials,
158+
self._host,
159+
credentials=self._credentials,
178160
credentials_file=credentials_file,
161+
scopes=self._scopes,
179162
ssl_credentials=self._ssl_channel_credentials,
180-
scopes=scopes or self.AUTH_SCOPES,
181163
quota_project_id=quota_project_id,
182164
options=[
183165
("grpc.max_send_message_length", -1),
184166
("grpc.max_receive_message_length", -1),
185167
],
186168
)
187169

188-
self._stubs = {} # type: Dict[str, Callable]
189-
190-
# Run the base constructor.
191-
super().__init__(
192-
host=host,
193-
credentials=credentials,
194-
credentials_file=credentials_file,
195-
scopes=scopes or self.AUTH_SCOPES,
196-
quota_project_id=quota_project_id,
197-
client_info=client_info,
198-
)
170+
# Wrap messages. This must be done after self._grpc_channel exists
171+
self._prep_wrapped_messages(client_info)
199172

200173
@classmethod
201174
def create_channel(
@@ -209,7 +182,7 @@ def create_channel(
209182
) -> grpc.Channel:
210183
"""Create and return a gRPC channel object.
211184
Args:
212-
address (Optional[str]): The host for the channel to use.
185+
host (Optional[str]): The host for the channel to use.
213186
credentials (Optional[~.Credentials]): The
214187
authorization credentials to attach to requests. These
215188
credentials identify this application to the service. If

google/cloud/texttospeech_v1/services/text_to_speech/transports/grpc_asyncio.py

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def create_channel(
6161
) -> aio.Channel:
6262
"""Create and return a gRPC AsyncIO channel object.
6363
Args:
64-
address (Optional[str]): The host for the channel to use.
64+
host (Optional[str]): The host for the channel to use.
6565
credentials (Optional[~.Credentials]): The
6666
authorization credentials to attach to requests. These
6767
credentials identify this application to the service. If
@@ -139,10 +139,10 @@ def __init__(
139139
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
140140
quota_project_id (Optional[str]): An optional project to use for billing
141141
and quota.
142-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
143-
The client info used to send a user-agent string along with
144-
API requests. If ``None``, then default info will be used.
145-
Generally, you only need to set this if you're developing
142+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
143+
The client info used to send a user-agent string along with
144+
API requests. If ``None``, then default info will be used.
145+
Generally, you only need to set this if you're developing
146146
your own client library.
147147
148148
Raises:
@@ -151,96 +151,69 @@ def __init__(
151151
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
152152
and ``credentials_file`` are passed.
153153
"""
154+
self._grpc_channel = None
154155
self._ssl_channel_credentials = ssl_channel_credentials
156+
self._stubs: Dict[str, Callable] = {}
155157

156158
if api_mtls_endpoint:
157159
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
158160
if client_cert_source:
159161
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
160162

161163
if channel:
162-
# Sanity check: Ensure that channel and credentials are not both
163-
# provided.
164+
# Ignore credentials if a channel was passed.
164165
credentials = False
165-
166166
# If a channel was explicitly provided, set it.
167167
self._grpc_channel = channel
168168
self._ssl_channel_credentials = None
169-
elif api_mtls_endpoint:
170-
host = (
171-
api_mtls_endpoint
172-
if ":" in api_mtls_endpoint
173-
else api_mtls_endpoint + ":443"
174-
)
175-
176-
if credentials is None:
177-
credentials, _ = auth.default(
178-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
179-
)
180-
181-
# Create SSL credentials with client_cert_source or application
182-
# default SSL credentials.
183-
if client_cert_source:
184-
cert, key = client_cert_source()
185-
ssl_credentials = grpc.ssl_channel_credentials(
186-
certificate_chain=cert, private_key=key
187-
)
188-
else:
189-
ssl_credentials = SslCredentials().ssl_credentials
190169

191-
# create a new channel. The provided one is ignored.
192-
self._grpc_channel = type(self).create_channel(
193-
host,
194-
credentials=credentials,
195-
credentials_file=credentials_file,
196-
ssl_credentials=ssl_credentials,
197-
scopes=scopes or self.AUTH_SCOPES,
198-
quota_project_id=quota_project_id,
199-
options=[
200-
("grpc.max_send_message_length", -1),
201-
("grpc.max_receive_message_length", -1),
202-
],
203-
)
204-
self._ssl_channel_credentials = ssl_credentials
205170
else:
206-
host = host if ":" in host else host + ":443"
171+
if api_mtls_endpoint:
172+
host = api_mtls_endpoint
173+
174+
# Create SSL credentials with client_cert_source or application
175+
# default SSL credentials.
176+
if client_cert_source:
177+
cert, key = client_cert_source()
178+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
179+
certificate_chain=cert, private_key=key
180+
)
181+
else:
182+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
207183

208-
if credentials is None:
209-
credentials, _ = auth.default(
210-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
211-
)
184+
else:
185+
if client_cert_source_for_mtls and not ssl_channel_credentials:
186+
cert, key = client_cert_source_for_mtls()
187+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
188+
certificate_chain=cert, private_key=key
189+
)
212190

213-
if client_cert_source_for_mtls and not ssl_channel_credentials:
214-
cert, key = client_cert_source_for_mtls()
215-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
216-
certificate_chain=cert, private_key=key
217-
)
191+
# The base transport sets the host, credentials and scopes
192+
super().__init__(
193+
host=host,
194+
credentials=credentials,
195+
credentials_file=credentials_file,
196+
scopes=scopes,
197+
quota_project_id=quota_project_id,
198+
client_info=client_info,
199+
)
218200

219-
# create a new channel. The provided one is ignored.
201+
if not self._grpc_channel:
220202
self._grpc_channel = type(self).create_channel(
221-
host,
222-
credentials=credentials,
203+
self._host,
204+
credentials=self._credentials,
223205
credentials_file=credentials_file,
206+
scopes=self._scopes,
224207
ssl_credentials=self._ssl_channel_credentials,
225-
scopes=scopes or self.AUTH_SCOPES,
226208
quota_project_id=quota_project_id,
227209
options=[
228210
("grpc.max_send_message_length", -1),
229211
("grpc.max_receive_message_length", -1),
230212
],
231213
)
232214

233-
# Run the base constructor.
234-
super().__init__(
235-
host=host,
236-
credentials=credentials,
237-
credentials_file=credentials_file,
238-
scopes=scopes or self.AUTH_SCOPES,
239-
quota_project_id=quota_project_id,
240-
client_info=client_info,
241-
)
242-
243-
self._stubs = {}
215+
# Wrap messages. This must be done after self._grpc_channel exists
216+
self._prep_wrapped_messages(client_info)
244217

245218
@property
246219
def grpc_channel(self) -> aio.Channel:

0 commit comments

Comments
 (0)