Skip to content

Commit 1ae9c1b

Browse files
feat: add common resource helper methods; expose client transport (#55)
autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters.
1 parent 52edb98 commit 1ae9c1b

File tree

22 files changed

+869
-244
lines changed

22 files changed

+869
-244
lines changed

packages/google-cloud-language/docs/language_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 Language v1 API
33

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

packages/google-cloud-language/docs/language_v1beta2/types.rst

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

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

packages/google-cloud-language/google/cloud/language_v1/proto/language_service.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ service LanguageService {
100100
}
101101
}
102102

103-
// ################################################################ #
103+
104104
//
105105
// Represents the input to API methods.
106106
message Document {

packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,47 @@ class LanguageServiceAsyncClient:
4545
DEFAULT_ENDPOINT = LanguageServiceClient.DEFAULT_ENDPOINT
4646
DEFAULT_MTLS_ENDPOINT = LanguageServiceClient.DEFAULT_MTLS_ENDPOINT
4747

48+
common_billing_account_path = staticmethod(
49+
LanguageServiceClient.common_billing_account_path
50+
)
51+
parse_common_billing_account_path = staticmethod(
52+
LanguageServiceClient.parse_common_billing_account_path
53+
)
54+
55+
common_folder_path = staticmethod(LanguageServiceClient.common_folder_path)
56+
parse_common_folder_path = staticmethod(
57+
LanguageServiceClient.parse_common_folder_path
58+
)
59+
60+
common_organization_path = staticmethod(
61+
LanguageServiceClient.common_organization_path
62+
)
63+
parse_common_organization_path = staticmethod(
64+
LanguageServiceClient.parse_common_organization_path
65+
)
66+
67+
common_project_path = staticmethod(LanguageServiceClient.common_project_path)
68+
parse_common_project_path = staticmethod(
69+
LanguageServiceClient.parse_common_project_path
70+
)
71+
72+
common_location_path = staticmethod(LanguageServiceClient.common_location_path)
73+
parse_common_location_path = staticmethod(
74+
LanguageServiceClient.parse_common_location_path
75+
)
76+
4877
from_service_account_file = LanguageServiceClient.from_service_account_file
4978
from_service_account_json = from_service_account_file
5079

80+
@property
81+
def transport(self) -> LanguageServiceTransport:
82+
"""Return the transport used by the client instance.
83+
84+
Returns:
85+
LanguageServiceTransport: The transport used by the client instance.
86+
"""
87+
return self._client.transport
88+
5189
get_transport_class = functools.partial(
5290
type(LanguageServiceClient).get_transport_class, type(LanguageServiceClient)
5391
)
@@ -143,7 +181,8 @@ async def analyze_sentiment(
143181
# Create or coerce a protobuf request object.
144182
# Sanity check: If we got a request object, we should *not* have
145183
# gotten any keyword arguments that map to the request.
146-
if request is not None and any([document, encoding_type]):
184+
has_flattened_params = any([document, encoding_type])
185+
if request is not None and has_flattened_params:
147186
raise ValueError(
148187
"If the `request` argument is set, then none of "
149188
"the individual field arguments should be set."
@@ -168,7 +207,7 @@ async def analyze_sentiment(
168207
maximum=60.0,
169208
multiplier=1.3,
170209
predicate=retries.if_exception_type(
171-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
210+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
172211
),
173212
),
174213
default_timeout=600.0,
@@ -224,7 +263,8 @@ async def analyze_entities(
224263
# Create or coerce a protobuf request object.
225264
# Sanity check: If we got a request object, we should *not* have
226265
# gotten any keyword arguments that map to the request.
227-
if request is not None and any([document, encoding_type]):
266+
has_flattened_params = any([document, encoding_type])
267+
if request is not None and has_flattened_params:
228268
raise ValueError(
229269
"If the `request` argument is set, then none of "
230270
"the individual field arguments should be set."
@@ -249,7 +289,7 @@ async def analyze_entities(
249289
maximum=60.0,
250290
multiplier=1.3,
251291
predicate=retries.if_exception_type(
252-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
292+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
253293
),
254294
),
255295
default_timeout=600.0,
@@ -308,7 +348,8 @@ async def analyze_entity_sentiment(
308348
# Create or coerce a protobuf request object.
309349
# Sanity check: If we got a request object, we should *not* have
310350
# gotten any keyword arguments that map to the request.
311-
if request is not None and any([document, encoding_type]):
351+
has_flattened_params = any([document, encoding_type])
352+
if request is not None and has_flattened_params:
312353
raise ValueError(
313354
"If the `request` argument is set, then none of "
314355
"the individual field arguments should be set."
@@ -333,7 +374,7 @@ async def analyze_entity_sentiment(
333374
maximum=60.0,
334375
multiplier=1.3,
335376
predicate=retries.if_exception_type(
336-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
377+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
337378
),
338379
),
339380
default_timeout=600.0,
@@ -388,7 +429,8 @@ async def analyze_syntax(
388429
# Create or coerce a protobuf request object.
389430
# Sanity check: If we got a request object, we should *not* have
390431
# gotten any keyword arguments that map to the request.
391-
if request is not None and any([document, encoding_type]):
432+
has_flattened_params = any([document, encoding_type])
433+
if request is not None and has_flattened_params:
392434
raise ValueError(
393435
"If the `request` argument is set, then none of "
394436
"the individual field arguments should be set."
@@ -413,7 +455,7 @@ async def analyze_syntax(
413455
maximum=60.0,
414456
multiplier=1.3,
415457
predicate=retries.if_exception_type(
416-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
458+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
417459
),
418460
),
419461
default_timeout=600.0,
@@ -462,7 +504,8 @@ async def classify_text(
462504
# Create or coerce a protobuf request object.
463505
# Sanity check: If we got a request object, we should *not* have
464506
# gotten any keyword arguments that map to the request.
465-
if request is not None and any([document]):
507+
has_flattened_params = any([document])
508+
if request is not None and has_flattened_params:
466509
raise ValueError(
467510
"If the `request` argument is set, then none of "
468511
"the individual field arguments should be set."
@@ -485,7 +528,7 @@ async def classify_text(
485528
maximum=60.0,
486529
multiplier=1.3,
487530
predicate=retries.if_exception_type(
488-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
531+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
489532
),
490533
),
491534
default_timeout=600.0,
@@ -550,7 +593,8 @@ async def annotate_text(
550593
# Create or coerce a protobuf request object.
551594
# Sanity check: If we got a request object, we should *not* have
552595
# gotten any keyword arguments that map to the request.
553-
if request is not None and any([document, features, encoding_type]):
596+
has_flattened_params = any([document, features, encoding_type])
597+
if request is not None and has_flattened_params:
554598
raise ValueError(
555599
"If the `request` argument is set, then none of "
556600
"the individual field arguments should be set."
@@ -577,7 +621,7 @@ async def annotate_text(
577621
maximum=60.0,
578622
multiplier=1.3,
579623
predicate=retries.if_exception_type(
580-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
624+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
581625
),
582626
),
583627
default_timeout=600.0,

packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py

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

132132
from_service_account_json = from_service_account_file
133133

134+
@property
135+
def transport(self) -> LanguageServiceTransport:
136+
"""Return the transport used by the client instance.
137+
138+
Returns:
139+
LanguageServiceTransport: The transport used by the client instance.
140+
"""
141+
return self._transport
142+
143+
@staticmethod
144+
def common_billing_account_path(billing_account: str,) -> str:
145+
"""Return a fully-qualified billing_account string."""
146+
return "billingAccounts/{billing_account}".format(
147+
billing_account=billing_account,
148+
)
149+
150+
@staticmethod
151+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
152+
"""Parse a billing_account path into its component segments."""
153+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
154+
return m.groupdict() if m else {}
155+
156+
@staticmethod
157+
def common_folder_path(folder: str,) -> str:
158+
"""Return a fully-qualified folder string."""
159+
return "folders/{folder}".format(folder=folder,)
160+
161+
@staticmethod
162+
def parse_common_folder_path(path: str) -> Dict[str, str]:
163+
"""Parse a folder path into its component segments."""
164+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
165+
return m.groupdict() if m else {}
166+
167+
@staticmethod
168+
def common_organization_path(organization: str,) -> str:
169+
"""Return a fully-qualified organization string."""
170+
return "organizations/{organization}".format(organization=organization,)
171+
172+
@staticmethod
173+
def parse_common_organization_path(path: str) -> Dict[str, str]:
174+
"""Parse a organization path into its component segments."""
175+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
176+
return m.groupdict() if m else {}
177+
178+
@staticmethod
179+
def common_project_path(project: str,) -> str:
180+
"""Return a fully-qualified project string."""
181+
return "projects/{project}".format(project=project,)
182+
183+
@staticmethod
184+
def parse_common_project_path(path: str) -> Dict[str, str]:
185+
"""Parse a project path into its component segments."""
186+
m = re.match(r"^projects/(?P<project>.+?)$", path)
187+
return m.groupdict() if m else {}
188+
189+
@staticmethod
190+
def common_location_path(project: str, location: str,) -> str:
191+
"""Return a fully-qualified location string."""
192+
return "projects/{project}/locations/{location}".format(
193+
project=project, location=location,
194+
)
195+
196+
@staticmethod
197+
def parse_common_location_path(path: str) -> Dict[str, str]:
198+
"""Parse a location path into its component segments."""
199+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
200+
return m.groupdict() if m else {}
201+
134202
def __init__(
135203
self,
136204
*,
@@ -166,10 +234,10 @@ def __init__(
166234
not provided, the default SSL client certificate will be used if
167235
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
168236
set, no client certificate will be used.
169-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
170-
The client info used to send a user-agent string along with
171-
API requests. If ``None``, then default info will be used.
172-
Generally, you only need to set this if you're developing
237+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
238+
The client info used to send a user-agent string along with
239+
API requests. If ``None``, then default info will be used.
240+
Generally, you only need to set this if you're developing
173241
your own client library.
174242
175243
Raises:

packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _prep_wrapped_messages(self, client_info):
114114
maximum=60.0,
115115
multiplier=1.3,
116116
predicate=retries.if_exception_type(
117-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
117+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
118118
),
119119
),
120120
default_timeout=600.0,
@@ -127,7 +127,7 @@ def _prep_wrapped_messages(self, client_info):
127127
maximum=60.0,
128128
multiplier=1.3,
129129
predicate=retries.if_exception_type(
130-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
130+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
131131
),
132132
),
133133
default_timeout=600.0,
@@ -140,7 +140,7 @@ def _prep_wrapped_messages(self, client_info):
140140
maximum=60.0,
141141
multiplier=1.3,
142142
predicate=retries.if_exception_type(
143-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
143+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
144144
),
145145
),
146146
default_timeout=600.0,
@@ -153,7 +153,7 @@ def _prep_wrapped_messages(self, client_info):
153153
maximum=60.0,
154154
multiplier=1.3,
155155
predicate=retries.if_exception_type(
156-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
156+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
157157
),
158158
),
159159
default_timeout=600.0,
@@ -166,7 +166,7 @@ def _prep_wrapped_messages(self, client_info):
166166
maximum=60.0,
167167
multiplier=1.3,
168168
predicate=retries.if_exception_type(
169-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
169+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
170170
),
171171
),
172172
default_timeout=600.0,
@@ -179,7 +179,7 @@ def _prep_wrapped_messages(self, client_info):
179179
maximum=60.0,
180180
multiplier=1.3,
181181
predicate=retries.if_exception_type(
182-
exceptions.ServiceUnavailable, exceptions.DeadlineExceeded,
182+
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
183183
),
184184
),
185185
default_timeout=600.0,

packages/google-cloud-language/google/cloud/language_v1/services/language_service/transports/grpc.py

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

110112
# If a channel was explicitly provided, set it.
111113
self._grpc_channel = channel
114+
self._ssl_channel_credentials = None
112115
elif api_mtls_endpoint:
113116
warnings.warn(
114117
"api_mtls_endpoint and client_cert_source are deprecated",
@@ -145,6 +148,7 @@ def __init__(
145148
scopes=scopes or self.AUTH_SCOPES,
146149
quota_project_id=quota_project_id,
147150
)
151+
self._ssl_channel_credentials = ssl_credentials
148152
else:
149153
host = host if ":" in host else host + ":443"
150154

@@ -222,12 +226,8 @@ def create_channel(
222226

223227
@property
224228
def grpc_channel(self) -> grpc.Channel:
225-
"""Create the channel designed to connect to this service.
226-
227-
This property caches on the instance; repeated calls return
228-
the same channel.
229+
"""Return the channel designed to connect to this service.
229230
"""
230-
# Return the channel from cache.
231231
return self._grpc_channel
232232

233233
@property

0 commit comments

Comments
 (0)