google-maps-routeoptimization 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {google_maps_routeoptimization-0.2.0/google_maps_routeoptimization.egg-info → google_maps_routeoptimization-0.4.0}/PKG-INFO +6 -8
  2. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/README.rst +2 -2
  3. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization/gapic_version.py +1 -1
  4. google_maps_routeoptimization-0.4.0/google/maps/routeoptimization_v1/__init__.py +202 -0
  5. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/gapic_version.py +1 -1
  6. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/async_client.py +22 -12
  7. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/client.py +61 -40
  8. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/transports/base.py +15 -6
  9. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/transports/grpc.py +17 -13
  10. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/transports/grpc_asyncio.py +16 -12
  11. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/transports/rest.py +20 -22
  12. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/types/route_optimization_service.py +69 -59
  13. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0/google_maps_routeoptimization.egg-info}/PKG-INFO +6 -8
  14. google_maps_routeoptimization-0.4.0/google_maps_routeoptimization.egg-info/requires.txt +11 -0
  15. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/setup.py +3 -5
  16. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/tests/unit/gapic/routeoptimization_v1/test_route_optimization.py +390 -137
  17. google_maps_routeoptimization-0.2.0/google/maps/routeoptimization_v1/__init__.py +0 -97
  18. google_maps_routeoptimization-0.2.0/google_maps_routeoptimization.egg-info/requires.txt +0 -11
  19. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/LICENSE +0 -0
  20. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/MANIFEST.in +0 -0
  21. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization/__init__.py +0 -0
  22. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization/py.typed +0 -0
  23. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/gapic_metadata.json +0 -0
  24. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/py.typed +0 -0
  25. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/__init__.py +0 -0
  26. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/__init__.py +0 -0
  27. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/transports/__init__.py +0 -0
  28. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/services/route_optimization/transports/rest_base.py +0 -0
  29. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google/maps/routeoptimization_v1/types/__init__.py +0 -0
  30. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google_maps_routeoptimization.egg-info/SOURCES.txt +0 -0
  31. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google_maps_routeoptimization.egg-info/dependency_links.txt +0 -0
  32. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google_maps_routeoptimization.egg-info/not-zip-safe +0 -0
  33. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/google_maps_routeoptimization.egg-info/top_level.txt +0 -0
  34. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/setup.cfg +0 -0
  35. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/tests/__init__.py +0 -0
  36. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/tests/unit/__init__.py +0 -0
  37. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/tests/unit/gapic/__init__.py +0 -0
  38. {google_maps_routeoptimization-0.2.0 → google_maps_routeoptimization-0.4.0}/tests/unit/gapic/routeoptimization_v1/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-maps-routeoptimization
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Google Maps Routeoptimization API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-maps-routeoptimization
6
6
  Author: Google LLC
@@ -12,8 +12,6 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.7
16
- Classifier: Programming Language :: Python :: 3.8
17
15
  Classifier: Programming Language :: Python :: 3.9
18
16
  Classifier: Programming Language :: Python :: 3.10
19
17
  Classifier: Programming Language :: Python :: 3.11
@@ -22,15 +20,15 @@ Classifier: Programming Language :: Python :: 3.13
22
20
  Classifier: Programming Language :: Python :: 3.14
23
21
  Classifier: Operating System :: OS Independent
24
22
  Classifier: Topic :: Internet
25
- Requires-Python: >=3.7
23
+ Requires-Python: >=3.9
26
24
  License-File: LICENSE
27
- Requires-Dist: google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.10.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,<3.0.0,>=1.34.1
25
+ Requires-Dist: google-api-core[grpc]<3.0.0,>=2.11.0
28
26
  Requires-Dist: google-auth!=2.24.0,!=2.25.0,<3.0.0,>=2.14.1
29
27
  Requires-Dist: grpcio<2.0.0,>=1.33.2
30
28
  Requires-Dist: grpcio<2.0.0,>=1.75.1; python_version >= "3.14"
31
29
  Requires-Dist: proto-plus<2.0.0,>=1.22.3
32
30
  Requires-Dist: proto-plus<2.0.0,>=1.25.0; python_version >= "3.13"
33
- Requires-Dist: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<7.0.0,>=3.20.2
31
+ Requires-Dist: protobuf<8.0.0,>=4.25.8
34
32
  Dynamic: author
35
33
  Dynamic: author-email
36
34
  Dynamic: classifier
@@ -106,14 +104,14 @@ Supported Python Versions
106
104
  Our client libraries are compatible with all current `active`_ and `maintenance`_ versions of
107
105
  Python.
108
106
 
109
- Python >= 3.7, including 3.14
107
+ Python >= 3.9, including 3.14
110
108
 
111
109
  .. _active: https://devguide.python.org/devcycle/#in-development-main-branch
112
110
  .. _maintenance: https://devguide.python.org/devcycle/#maintenance-branches
113
111
 
114
112
  Unsupported Python Versions
115
113
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
116
- Python <= 3.6
114
+ Python <= 3.8
117
115
 
118
116
  If you are using an `end-of-life`_
119
117
  version of Python, we recommend that you update as soon as possible to an actively supported version.
@@ -61,14 +61,14 @@ Supported Python Versions
61
61
  Our client libraries are compatible with all current `active`_ and `maintenance`_ versions of
62
62
  Python.
63
63
 
64
- Python >= 3.7, including 3.14
64
+ Python >= 3.9, including 3.14
65
65
 
66
66
  .. _active: https://devguide.python.org/devcycle/#in-development-main-branch
67
67
  .. _maintenance: https://devguide.python.org/devcycle/#maintenance-branches
68
68
 
69
69
  Unsupported Python Versions
70
70
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
71
- Python <= 3.6
71
+ Python <= 3.8
72
72
 
73
73
  If you are using an `end-of-life`_
74
74
  version of Python, we recommend that you update as soon as possible to an actively supported version.
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- __version__ = "0.2.0" # {x-release-please-version}
16
+ __version__ = "0.4.0" # {x-release-please-version}
@@ -0,0 +1,202 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2025 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import sys
17
+
18
+ import google.api_core as api_core
19
+
20
+ from google.maps.routeoptimization_v1 import gapic_version as package_version
21
+
22
+ __version__ = package_version.__version__
23
+
24
+ if sys.version_info >= (3, 8): # pragma: NO COVER
25
+ from importlib import metadata
26
+ else: # pragma: NO COVER
27
+ # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
28
+ # this code path once we drop support for Python 3.7
29
+ import importlib_metadata as metadata
30
+
31
+
32
+ from .services.route_optimization import (
33
+ RouteOptimizationAsyncClient,
34
+ RouteOptimizationClient,
35
+ )
36
+ from .types.route_optimization_service import (
37
+ AggregatedMetrics,
38
+ BatchOptimizeToursMetadata,
39
+ BatchOptimizeToursRequest,
40
+ BatchOptimizeToursResponse,
41
+ BreakRule,
42
+ DataFormat,
43
+ DistanceLimit,
44
+ GcsDestination,
45
+ GcsSource,
46
+ InjectedSolutionConstraint,
47
+ InputConfig,
48
+ Location,
49
+ OptimizeToursLongRunningMetadata,
50
+ OptimizeToursRequest,
51
+ OptimizeToursResponse,
52
+ OptimizeToursUriMetadata,
53
+ OptimizeToursUriRequest,
54
+ OptimizeToursUriResponse,
55
+ OptimizeToursValidationError,
56
+ OutputConfig,
57
+ RouteModifiers,
58
+ Shipment,
59
+ ShipmentModel,
60
+ ShipmentRoute,
61
+ ShipmentTypeIncompatibility,
62
+ ShipmentTypeRequirement,
63
+ SkippedShipment,
64
+ TimeWindow,
65
+ TransitionAttributes,
66
+ Uri,
67
+ Vehicle,
68
+ VehicleFullness,
69
+ Waypoint,
70
+ )
71
+
72
+ if hasattr(api_core, "check_python_version") and hasattr(
73
+ api_core, "check_dependency_versions"
74
+ ): # pragma: NO COVER
75
+ api_core.check_python_version("google.maps.routeoptimization_v1") # type: ignore
76
+ api_core.check_dependency_versions("google.maps.routeoptimization_v1") # type: ignore
77
+ else: # pragma: NO COVER
78
+ # An older version of api_core is installed which does not define the
79
+ # functions above. We do equivalent checks manually.
80
+ try:
81
+ import sys
82
+ import warnings
83
+
84
+ _py_version_str = sys.version.split()[0]
85
+ _package_label = "google.maps.routeoptimization_v1"
86
+ if sys.version_info < (3, 9):
87
+ warnings.warn(
88
+ "You are using a non-supported Python version "
89
+ + f"({_py_version_str}). Google will not post any further "
90
+ + f"updates to {_package_label} supporting this Python version. "
91
+ + "Please upgrade to the latest Python version, or at "
92
+ + f"least to Python 3.9, and then update {_package_label}.",
93
+ FutureWarning,
94
+ )
95
+ if sys.version_info[:2] == (3, 9):
96
+ warnings.warn(
97
+ f"You are using a Python version ({_py_version_str}) "
98
+ + f"which Google will stop supporting in {_package_label} in "
99
+ + "January 2026. Please "
100
+ + "upgrade to the latest Python version, or at "
101
+ + "least to Python 3.10, before then, and "
102
+ + f"then update {_package_label}.",
103
+ FutureWarning,
104
+ )
105
+
106
+ def parse_version_to_tuple(version_string: str):
107
+ """Safely converts a semantic version string to a comparable tuple of integers.
108
+ Example: "4.25.8" -> (4, 25, 8)
109
+ Ignores non-numeric parts and handles common version formats.
110
+ Args:
111
+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
112
+ Returns:
113
+ Tuple of integers for the parsed version string.
114
+ """
115
+ parts = []
116
+ for part in version_string.split("."):
117
+ try:
118
+ parts.append(int(part))
119
+ except ValueError:
120
+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
121
+ # This is a simplification compared to 'packaging.parse_version', but sufficient
122
+ # for comparing strictly numeric semantic versions.
123
+ break
124
+ return tuple(parts)
125
+
126
+ def _get_version(dependency_name):
127
+ try:
128
+ version_string: str = metadata.version(dependency_name)
129
+ parsed_version = parse_version_to_tuple(version_string)
130
+ return (parsed_version, version_string)
131
+ except Exception:
132
+ # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
133
+ # or errors during parse_version_to_tuple
134
+ return (None, "--")
135
+
136
+ _dependency_package = "google.protobuf"
137
+ _next_supported_version = "4.25.8"
138
+ _next_supported_version_tuple = (4, 25, 8)
139
+ _recommendation = " (we recommend 6.x)"
140
+ (_version_used, _version_used_string) = _get_version(_dependency_package)
141
+ if _version_used and _version_used < _next_supported_version_tuple:
142
+ warnings.warn(
143
+ f"Package {_package_label} depends on "
144
+ + f"{_dependency_package}, currently installed at version "
145
+ + f"{_version_used_string}. Future updates to "
146
+ + f"{_package_label} will require {_dependency_package} at "
147
+ + f"version {_next_supported_version} or higher{_recommendation}."
148
+ + " Please ensure "
149
+ + "that either (a) your Python environment doesn't pin the "
150
+ + f"version of {_dependency_package}, so that updates to "
151
+ + f"{_package_label} can require the higher version, or "
152
+ + "(b) you manually update your Python environment to use at "
153
+ + f"least version {_next_supported_version} of "
154
+ + f"{_dependency_package}.",
155
+ FutureWarning,
156
+ )
157
+ except Exception:
158
+ warnings.warn(
159
+ "Could not determine the version of Python "
160
+ + "currently being used. To continue receiving "
161
+ + "updates for {_package_label}, ensure you are "
162
+ + "using a supported version of Python; see "
163
+ + "https://devguide.python.org/versions/"
164
+ )
165
+
166
+ __all__ = (
167
+ "RouteOptimizationAsyncClient",
168
+ "AggregatedMetrics",
169
+ "BatchOptimizeToursMetadata",
170
+ "BatchOptimizeToursRequest",
171
+ "BatchOptimizeToursResponse",
172
+ "BreakRule",
173
+ "DataFormat",
174
+ "DistanceLimit",
175
+ "GcsDestination",
176
+ "GcsSource",
177
+ "InjectedSolutionConstraint",
178
+ "InputConfig",
179
+ "Location",
180
+ "OptimizeToursLongRunningMetadata",
181
+ "OptimizeToursRequest",
182
+ "OptimizeToursResponse",
183
+ "OptimizeToursUriMetadata",
184
+ "OptimizeToursUriRequest",
185
+ "OptimizeToursUriResponse",
186
+ "OptimizeToursValidationError",
187
+ "OutputConfig",
188
+ "RouteModifiers",
189
+ "RouteOptimizationClient",
190
+ "Shipment",
191
+ "ShipmentModel",
192
+ "ShipmentRoute",
193
+ "ShipmentTypeIncompatibility",
194
+ "ShipmentTypeRequirement",
195
+ "SkippedShipment",
196
+ "TimeWindow",
197
+ "TransitionAttributes",
198
+ "Uri",
199
+ "Vehicle",
200
+ "VehicleFullness",
201
+ "Waypoint",
202
+ )
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- __version__ = "0.2.0" # {x-release-please-version}
16
+ __version__ = "0.4.0" # {x-release-please-version}
@@ -13,9 +13,9 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- from collections import OrderedDict
17
16
  import logging as std_logging
18
17
  import re
18
+ from collections import OrderedDict
19
19
  from typing import (
20
20
  Callable,
21
21
  Dict,
@@ -29,13 +29,13 @@ from typing import (
29
29
  Union,
30
30
  )
31
31
 
32
+ import google.protobuf
32
33
  from google.api_core import exceptions as core_exceptions
33
34
  from google.api_core import gapic_v1
34
35
  from google.api_core import retry_async as retries
35
36
  from google.api_core.client_options import ClientOptions
36
37
  from google.auth import credentials as ga_credentials # type: ignore
37
38
  from google.oauth2 import service_account # type: ignore
38
- import google.protobuf
39
39
 
40
40
  from google.maps.routeoptimization_v1 import gapic_version as package_version
41
41
 
@@ -44,8 +44,8 @@ try:
44
44
  except AttributeError: # pragma: NO COVER
45
45
  OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore
46
46
 
47
- from google.api_core import operation # type: ignore
48
- from google.api_core import operation_async # type: ignore
47
+ import google.api_core.operation as operation # type: ignore
48
+ import google.api_core.operation_async as operation_async # type: ignore
49
49
  from google.longrunning import operations_pb2 # type: ignore
50
50
 
51
51
  from google.maps.routeoptimization_v1.types import route_optimization_service
@@ -136,7 +136,10 @@ class RouteOptimizationAsyncClient:
136
136
  Returns:
137
137
  RouteOptimizationAsyncClient: The constructed client.
138
138
  """
139
- return RouteOptimizationClient.from_service_account_info.__func__(RouteOptimizationAsyncClient, info, *args, **kwargs) # type: ignore
139
+ sa_info_func = (
140
+ RouteOptimizationClient.from_service_account_info.__func__ # type: ignore
141
+ )
142
+ return sa_info_func(RouteOptimizationAsyncClient, info, *args, **kwargs)
140
143
 
141
144
  @classmethod
142
145
  def from_service_account_file(cls, filename: str, *args, **kwargs):
@@ -152,7 +155,10 @@ class RouteOptimizationAsyncClient:
152
155
  Returns:
153
156
  RouteOptimizationAsyncClient: The constructed client.
154
157
  """
155
- return RouteOptimizationClient.from_service_account_file.__func__(RouteOptimizationAsyncClient, filename, *args, **kwargs) # type: ignore
158
+ sa_file_func = (
159
+ RouteOptimizationClient.from_service_account_file.__func__ # type: ignore
160
+ )
161
+ return sa_file_func(RouteOptimizationAsyncClient, filename, *args, **kwargs)
156
162
 
157
163
  from_service_account_json = from_service_account_file
158
164
 
@@ -202,7 +208,7 @@ class RouteOptimizationAsyncClient:
202
208
  return self._client.transport
203
209
 
204
210
  @property
205
- def api_endpoint(self):
211
+ def api_endpoint(self) -> str:
206
212
  """Return the API endpoint used by the client instance.
207
213
 
208
214
  Returns:
@@ -819,7 +825,7 @@ class RouteOptimizationAsyncClient:
819
825
 
820
826
  async def get_operation(
821
827
  self,
822
- request: Optional[operations_pb2.GetOperationRequest] = None,
828
+ request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None,
823
829
  *,
824
830
  retry: OptionalRetry = gapic_v1.method.DEFAULT,
825
831
  timeout: Union[float, object] = gapic_v1.method.DEFAULT,
@@ -845,8 +851,12 @@ class RouteOptimizationAsyncClient:
845
851
  # Create or coerce a protobuf request object.
846
852
  # The request isn't a proto-plus wrapped type,
847
853
  # so it must be constructed via keyword expansion.
848
- if isinstance(request, dict):
849
- request = operations_pb2.GetOperationRequest(**request)
854
+ if request is None:
855
+ request_pb = operations_pb2.GetOperationRequest()
856
+ elif isinstance(request, dict):
857
+ request_pb = operations_pb2.GetOperationRequest(**request)
858
+ else:
859
+ request_pb = request
850
860
 
851
861
  # Wrap the RPC method; this adds retry and timeout information,
852
862
  # and friendly error handling.
@@ -855,7 +865,7 @@ class RouteOptimizationAsyncClient:
855
865
  # Certain fields should be provided within the metadata header;
856
866
  # add these here.
857
867
  metadata = tuple(metadata) + (
858
- gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
868
+ gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)),
859
869
  )
860
870
 
861
871
  # Validate the universe domain.
@@ -863,7 +873,7 @@ class RouteOptimizationAsyncClient:
863
873
 
864
874
  # Send the request.
865
875
  response = await rpc(
866
- request,
876
+ request_pb,
867
877
  retry=retry,
868
878
  timeout=timeout,
869
879
  metadata=metadata,
@@ -13,12 +13,13 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- from collections import OrderedDict
17
- from http import HTTPStatus
18
16
  import json
19
17
  import logging as std_logging
20
18
  import os
21
19
  import re
20
+ import warnings
21
+ from collections import OrderedDict
22
+ from http import HTTPStatus
22
23
  from typing import (
23
24
  Callable,
24
25
  Dict,
@@ -32,8 +33,8 @@ from typing import (
32
33
  Union,
33
34
  cast,
34
35
  )
35
- import warnings
36
36
 
37
+ import google.protobuf
37
38
  from google.api_core import client_options as client_options_lib
38
39
  from google.api_core import exceptions as core_exceptions
39
40
  from google.api_core import gapic_v1
@@ -43,7 +44,6 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore
43
44
  from google.auth.transport import mtls # type: ignore
44
45
  from google.auth.transport.grpc import SslCredentials # type: ignore
45
46
  from google.oauth2 import service_account # type: ignore
46
- import google.protobuf
47
47
 
48
48
  from google.maps.routeoptimization_v1 import gapic_version as package_version
49
49
 
@@ -61,8 +61,8 @@ except ImportError: # pragma: NO COVER
61
61
 
62
62
  _LOGGER = std_logging.getLogger(__name__)
63
63
 
64
- from google.api_core import operation # type: ignore
65
- from google.api_core import operation_async # type: ignore
64
+ import google.api_core.operation as operation # type: ignore
65
+ import google.api_core.operation_async as operation_async # type: ignore
66
66
  from google.longrunning import operations_pb2 # type: ignore
67
67
 
68
68
  from google.maps.routeoptimization_v1.types import route_optimization_service
@@ -81,9 +81,7 @@ class RouteOptimizationClientMeta(type):
81
81
  objects.
82
82
  """
83
83
 
84
- _transport_registry = (
85
- OrderedDict()
86
- ) # type: Dict[str, Type[RouteOptimizationTransport]]
84
+ _transport_registry = OrderedDict() # type: Dict[str, Type[RouteOptimizationTransport]]
87
85
  _transport_registry["grpc"] = RouteOptimizationGrpcTransport
88
86
  _transport_registry["grpc_asyncio"] = RouteOptimizationGrpcAsyncIOTransport
89
87
  _transport_registry["rest"] = RouteOptimizationRestTransport
@@ -136,7 +134,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
136
134
  """
137
135
 
138
136
  @staticmethod
139
- def _get_default_mtls_endpoint(api_endpoint):
137
+ def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]:
140
138
  """Converts api endpoint to mTLS endpoint.
141
139
 
142
140
  Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
@@ -144,7 +142,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
144
142
  Args:
145
143
  api_endpoint (Optional[str]): the api endpoint to convert.
146
144
  Returns:
147
- str: converted mTLS api endpoint.
145
+ Optional[str]: converted mTLS api endpoint.
148
146
  """
149
147
  if not api_endpoint:
150
148
  return api_endpoint
@@ -154,6 +152,10 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
154
152
  )
155
153
 
156
154
  m = mtls_endpoint_re.match(api_endpoint)
155
+ if m is None:
156
+ # Could not parse api_endpoint; return as-is.
157
+ return api_endpoint
158
+
157
159
  name, mtls, sandbox, googledomain = m.groups()
158
160
  if mtls or not googledomain:
159
161
  return api_endpoint
@@ -174,6 +176,34 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
174
176
  _DEFAULT_ENDPOINT_TEMPLATE = "routeoptimization.{UNIVERSE_DOMAIN}"
175
177
  _DEFAULT_UNIVERSE = "googleapis.com"
176
178
 
179
+ @staticmethod
180
+ def _use_client_cert_effective():
181
+ """Returns whether client certificate should be used for mTLS if the
182
+ google-auth version supports should_use_client_cert automatic mTLS enablement.
183
+
184
+ Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.
185
+
186
+ Returns:
187
+ bool: whether client certificate should be used for mTLS
188
+ Raises:
189
+ ValueError: (If using a version of google-auth without should_use_client_cert and
190
+ GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
191
+ """
192
+ # check if google-auth version supports should_use_client_cert for automatic mTLS enablement
193
+ if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
194
+ return mtls.should_use_client_cert()
195
+ else: # pragma: NO COVER
196
+ # if unsupported, fallback to reading from env var
197
+ use_client_cert_str = os.getenv(
198
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
199
+ ).lower()
200
+ if use_client_cert_str not in ("true", "false"):
201
+ raise ValueError(
202
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
203
+ " either `true` or `false`"
204
+ )
205
+ return use_client_cert_str == "true"
206
+
177
207
  @classmethod
178
208
  def from_service_account_info(cls, info: dict, *args, **kwargs):
179
209
  """Creates an instance of this client using the provided credentials
@@ -339,12 +369,8 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
339
369
  )
340
370
  if client_options is None:
341
371
  client_options = client_options_lib.ClientOptions()
342
- use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
372
+ use_client_cert = RouteOptimizationClient._use_client_cert_effective()
343
373
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
344
- if use_client_cert not in ("true", "false"):
345
- raise ValueError(
346
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
347
- )
348
374
  if use_mtls_endpoint not in ("auto", "never", "always"):
349
375
  raise MutualTLSChannelError(
350
376
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
@@ -352,7 +378,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
352
378
 
353
379
  # Figure out the client cert source to use.
354
380
  client_cert_source = None
355
- if use_client_cert == "true":
381
+ if use_client_cert:
356
382
  if client_options.client_cert_source:
357
383
  client_cert_source = client_options.client_cert_source
358
384
  elif mtls.has_default_client_cert_source():
@@ -384,20 +410,14 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
384
410
  google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
385
411
  is not any of ["auto", "never", "always"].
386
412
  """
387
- use_client_cert = os.getenv(
388
- "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
389
- ).lower()
413
+ use_client_cert = RouteOptimizationClient._use_client_cert_effective()
390
414
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
391
415
  universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
392
- if use_client_cert not in ("true", "false"):
393
- raise ValueError(
394
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
395
- )
396
416
  if use_mtls_endpoint not in ("auto", "never", "always"):
397
417
  raise MutualTLSChannelError(
398
418
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
399
419
  )
400
- return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
420
+ return use_client_cert, use_mtls_endpoint, universe_domain_env
401
421
 
402
422
  @staticmethod
403
423
  def _get_client_cert_source(provided_cert_source, use_cert_flag):
@@ -421,7 +441,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
421
441
  @staticmethod
422
442
  def _get_api_endpoint(
423
443
  api_override, client_cert_source, universe_domain, use_mtls_endpoint
424
- ):
444
+ ) -> str:
425
445
  """Return the API endpoint used by the client.
426
446
 
427
447
  Args:
@@ -518,7 +538,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
518
538
  error._details.append(json.dumps(cred_info))
519
539
 
520
540
  @property
521
- def api_endpoint(self):
541
+ def api_endpoint(self) -> str:
522
542
  """Return the API endpoint used by the client instance.
523
543
 
524
544
  Returns:
@@ -609,18 +629,16 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
609
629
 
610
630
  universe_domain_opt = getattr(self._client_options, "universe_domain", None)
611
631
 
612
- (
613
- self._use_client_cert,
614
- self._use_mtls_endpoint,
615
- self._universe_domain_env,
616
- ) = RouteOptimizationClient._read_environment_variables()
632
+ self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = (
633
+ RouteOptimizationClient._read_environment_variables()
634
+ )
617
635
  self._client_cert_source = RouteOptimizationClient._get_client_cert_source(
618
636
  self._client_options.client_cert_source, self._use_client_cert
619
637
  )
620
638
  self._universe_domain = RouteOptimizationClient._get_universe_domain(
621
639
  universe_domain_opt, self._universe_domain_env
622
640
  )
623
- self._api_endpoint = None # updated below, depending on `transport`
641
+ self._api_endpoint: str = "" # updated below, depending on `transport`
624
642
 
625
643
  # Initialize the universe domain validation.
626
644
  self._is_universe_domain_valid = False
@@ -648,8 +666,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
648
666
  )
649
667
  if self._client_options.scopes:
650
668
  raise ValueError(
651
- "When providing a transport instance, provide its scopes "
652
- "directly."
669
+ "When providing a transport instance, provide its scopes directly."
653
670
  )
654
671
  self._transport = cast(RouteOptimizationTransport, transport)
655
672
  self._api_endpoint = self._transport.host
@@ -1230,7 +1247,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
1230
1247
 
1231
1248
  def get_operation(
1232
1249
  self,
1233
- request: Optional[operations_pb2.GetOperationRequest] = None,
1250
+ request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None,
1234
1251
  *,
1235
1252
  retry: OptionalRetry = gapic_v1.method.DEFAULT,
1236
1253
  timeout: Union[float, object] = gapic_v1.method.DEFAULT,
@@ -1256,8 +1273,12 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
1256
1273
  # Create or coerce a protobuf request object.
1257
1274
  # The request isn't a proto-plus wrapped type,
1258
1275
  # so it must be constructed via keyword expansion.
1259
- if isinstance(request, dict):
1260
- request = operations_pb2.GetOperationRequest(**request)
1276
+ if request is None:
1277
+ request_pb = operations_pb2.GetOperationRequest()
1278
+ elif isinstance(request, dict):
1279
+ request_pb = operations_pb2.GetOperationRequest(**request)
1280
+ else:
1281
+ request_pb = request
1261
1282
 
1262
1283
  # Wrap the RPC method; this adds retry and timeout information,
1263
1284
  # and friendly error handling.
@@ -1266,7 +1287,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
1266
1287
  # Certain fields should be provided within the metadata header;
1267
1288
  # add these here.
1268
1289
  metadata = tuple(metadata) + (
1269
- gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1290
+ gapic_v1.routing_header.to_grpc_metadata((("name", request_pb.name),)),
1270
1291
  )
1271
1292
 
1272
1293
  # Validate the universe domain.
@@ -1275,7 +1296,7 @@ class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
1275
1296
  try:
1276
1297
  # Send the request.
1277
1298
  response = rpc(
1278
- request,
1299
+ request_pb,
1279
1300
  retry=retry,
1280
1301
  timeout=timeout,
1281
1302
  metadata=metadata,