Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/tasks_v2/services/cloud_tasks/transports/rest.py: 33%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

661 statements  

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# 

16import dataclasses 

17import json # type: ignore 

18import logging 

19from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union 

20import warnings 

21 

22from google.api_core import exceptions as core_exceptions 

23from google.api_core import gapic_v1, rest_helpers, rest_streaming 

24from google.api_core import retry as retries 

25from google.auth import credentials as ga_credentials # type: ignore 

26from google.auth.transport.requests import AuthorizedSession # type: ignore 

27from google.cloud.location import locations_pb2 # type: ignore 

28from google.iam.v1 import iam_policy_pb2 # type: ignore 

29from google.iam.v1 import policy_pb2 # type: ignore 

30import google.protobuf 

31from google.protobuf import empty_pb2 # type: ignore 

32from google.protobuf import json_format 

33from requests import __version__ as requests_version 

34 

35from google.cloud.tasks_v2.types import cloudtasks 

36from google.cloud.tasks_v2.types import queue 

37from google.cloud.tasks_v2.types import queue as gct_queue 

38from google.cloud.tasks_v2.types import task 

39from google.cloud.tasks_v2.types import task as gct_task 

40 

41from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

42from .rest_base import _BaseCloudTasksRestTransport 

43 

44try: 

45 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] 

46except AttributeError: # pragma: NO COVER 

47 OptionalRetry = Union[retries.Retry, object, None] # type: ignore 

48 

49try: 

50 from google.api_core import client_logging # type: ignore 

51 

52 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

53except ImportError: # pragma: NO COVER 

54 CLIENT_LOGGING_SUPPORTED = False 

55 

56_LOGGER = logging.getLogger(__name__) 

57 

58DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

59 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

60 grpc_version=None, 

61 rest_version=f"requests@{requests_version}", 

62) 

63 

64if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

65 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

66 

67 

68class CloudTasksRestInterceptor: 

69 """Interceptor for CloudTasks. 

70 

71 Interceptors are used to manipulate requests, request metadata, and responses 

72 in arbitrary ways. 

73 Example use cases include: 

74 * Logging 

75 * Verifying requests according to service or custom semantics 

76 * Stripping extraneous information from responses 

77 

78 These use cases and more can be enabled by injecting an 

79 instance of a custom subclass when constructing the CloudTasksRestTransport. 

80 

81 .. code-block:: python 

82 class MyCustomCloudTasksInterceptor(CloudTasksRestInterceptor): 

83 def pre_create_queue(self, request, metadata): 

84 logging.log(f"Received request: {request}") 

85 return request, metadata 

86 

87 def post_create_queue(self, response): 

88 logging.log(f"Received response: {response}") 

89 return response 

90 

91 def pre_create_task(self, request, metadata): 

92 logging.log(f"Received request: {request}") 

93 return request, metadata 

94 

95 def post_create_task(self, response): 

96 logging.log(f"Received response: {response}") 

97 return response 

98 

99 def pre_delete_queue(self, request, metadata): 

100 logging.log(f"Received request: {request}") 

101 return request, metadata 

102 

103 def pre_delete_task(self, request, metadata): 

104 logging.log(f"Received request: {request}") 

105 return request, metadata 

106 

107 def pre_get_iam_policy(self, request, metadata): 

108 logging.log(f"Received request: {request}") 

109 return request, metadata 

110 

111 def post_get_iam_policy(self, response): 

112 logging.log(f"Received response: {response}") 

113 return response 

114 

115 def pre_get_queue(self, request, metadata): 

116 logging.log(f"Received request: {request}") 

117 return request, metadata 

118 

119 def post_get_queue(self, response): 

120 logging.log(f"Received response: {response}") 

121 return response 

122 

123 def pre_get_task(self, request, metadata): 

124 logging.log(f"Received request: {request}") 

125 return request, metadata 

126 

127 def post_get_task(self, response): 

128 logging.log(f"Received response: {response}") 

129 return response 

130 

131 def pre_list_queues(self, request, metadata): 

132 logging.log(f"Received request: {request}") 

133 return request, metadata 

134 

135 def post_list_queues(self, response): 

136 logging.log(f"Received response: {response}") 

137 return response 

138 

139 def pre_list_tasks(self, request, metadata): 

140 logging.log(f"Received request: {request}") 

141 return request, metadata 

142 

143 def post_list_tasks(self, response): 

144 logging.log(f"Received response: {response}") 

145 return response 

146 

147 def pre_pause_queue(self, request, metadata): 

148 logging.log(f"Received request: {request}") 

149 return request, metadata 

150 

151 def post_pause_queue(self, response): 

152 logging.log(f"Received response: {response}") 

153 return response 

154 

155 def pre_purge_queue(self, request, metadata): 

156 logging.log(f"Received request: {request}") 

157 return request, metadata 

158 

159 def post_purge_queue(self, response): 

160 logging.log(f"Received response: {response}") 

161 return response 

162 

163 def pre_resume_queue(self, request, metadata): 

164 logging.log(f"Received request: {request}") 

165 return request, metadata 

166 

167 def post_resume_queue(self, response): 

168 logging.log(f"Received response: {response}") 

169 return response 

170 

171 def pre_run_task(self, request, metadata): 

172 logging.log(f"Received request: {request}") 

173 return request, metadata 

174 

175 def post_run_task(self, response): 

176 logging.log(f"Received response: {response}") 

177 return response 

178 

179 def pre_set_iam_policy(self, request, metadata): 

180 logging.log(f"Received request: {request}") 

181 return request, metadata 

182 

183 def post_set_iam_policy(self, response): 

184 logging.log(f"Received response: {response}") 

185 return response 

186 

187 def pre_test_iam_permissions(self, request, metadata): 

188 logging.log(f"Received request: {request}") 

189 return request, metadata 

190 

191 def post_test_iam_permissions(self, response): 

192 logging.log(f"Received response: {response}") 

193 return response 

194 

195 def pre_update_queue(self, request, metadata): 

196 logging.log(f"Received request: {request}") 

197 return request, metadata 

198 

199 def post_update_queue(self, response): 

200 logging.log(f"Received response: {response}") 

201 return response 

202 

203 transport = CloudTasksRestTransport(interceptor=MyCustomCloudTasksInterceptor()) 

204 client = CloudTasksClient(transport=transport) 

205 

206 

207 """ 

208 

209 def pre_create_queue( 

210 self, 

211 request: cloudtasks.CreateQueueRequest, 

212 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

213 ) -> Tuple[cloudtasks.CreateQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

214 """Pre-rpc interceptor for create_queue 

215 

216 Override in a subclass to manipulate the request or metadata 

217 before they are sent to the CloudTasks server. 

218 """ 

219 return request, metadata 

220 

221 def post_create_queue(self, response: gct_queue.Queue) -> gct_queue.Queue: 

222 """Post-rpc interceptor for create_queue 

223 

224 DEPRECATED. Please use the `post_create_queue_with_metadata` 

225 interceptor instead. 

226 

227 Override in a subclass to read or manipulate the response 

228 after it is returned by the CloudTasks server but before 

229 it is returned to user code. This `post_create_queue` interceptor runs 

230 before the `post_create_queue_with_metadata` interceptor. 

231 """ 

232 return response 

233 

234 def post_create_queue_with_metadata( 

235 self, 

236 response: gct_queue.Queue, 

237 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

238 ) -> Tuple[gct_queue.Queue, Sequence[Tuple[str, Union[str, bytes]]]]: 

239 """Post-rpc interceptor for create_queue 

240 

241 Override in a subclass to read or manipulate the response or metadata after it 

242 is returned by the CloudTasks server but before it is returned to user code. 

243 

244 We recommend only using this `post_create_queue_with_metadata` 

245 interceptor in new development instead of the `post_create_queue` interceptor. 

246 When both interceptors are used, this `post_create_queue_with_metadata` interceptor runs after the 

247 `post_create_queue` interceptor. The (possibly modified) response returned by 

248 `post_create_queue` will be passed to 

249 `post_create_queue_with_metadata`. 

250 """ 

251 return response, metadata 

252 

253 def pre_create_task( 

254 self, 

255 request: cloudtasks.CreateTaskRequest, 

256 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

257 ) -> Tuple[cloudtasks.CreateTaskRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

258 """Pre-rpc interceptor for create_task 

259 

260 Override in a subclass to manipulate the request or metadata 

261 before they are sent to the CloudTasks server. 

262 """ 

263 return request, metadata 

264 

265 def post_create_task(self, response: gct_task.Task) -> gct_task.Task: 

266 """Post-rpc interceptor for create_task 

267 

268 DEPRECATED. Please use the `post_create_task_with_metadata` 

269 interceptor instead. 

270 

271 Override in a subclass to read or manipulate the response 

272 after it is returned by the CloudTasks server but before 

273 it is returned to user code. This `post_create_task` interceptor runs 

274 before the `post_create_task_with_metadata` interceptor. 

275 """ 

276 return response 

277 

278 def post_create_task_with_metadata( 

279 self, response: gct_task.Task, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

280 ) -> Tuple[gct_task.Task, Sequence[Tuple[str, Union[str, bytes]]]]: 

281 """Post-rpc interceptor for create_task 

282 

283 Override in a subclass to read or manipulate the response or metadata after it 

284 is returned by the CloudTasks server but before it is returned to user code. 

285 

286 We recommend only using this `post_create_task_with_metadata` 

287 interceptor in new development instead of the `post_create_task` interceptor. 

288 When both interceptors are used, this `post_create_task_with_metadata` interceptor runs after the 

289 `post_create_task` interceptor. The (possibly modified) response returned by 

290 `post_create_task` will be passed to 

291 `post_create_task_with_metadata`. 

292 """ 

293 return response, metadata 

294 

295 def pre_delete_queue( 

296 self, 

297 request: cloudtasks.DeleteQueueRequest, 

298 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

299 ) -> Tuple[cloudtasks.DeleteQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

300 """Pre-rpc interceptor for delete_queue 

301 

302 Override in a subclass to manipulate the request or metadata 

303 before they are sent to the CloudTasks server. 

304 """ 

305 return request, metadata 

306 

307 def pre_delete_task( 

308 self, 

309 request: cloudtasks.DeleteTaskRequest, 

310 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

311 ) -> Tuple[cloudtasks.DeleteTaskRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

312 """Pre-rpc interceptor for delete_task 

313 

314 Override in a subclass to manipulate the request or metadata 

315 before they are sent to the CloudTasks server. 

316 """ 

317 return request, metadata 

318 

319 def pre_get_iam_policy( 

320 self, 

321 request: iam_policy_pb2.GetIamPolicyRequest, 

322 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

323 ) -> Tuple[ 

324 iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] 

325 ]: 

326 """Pre-rpc interceptor for get_iam_policy 

327 

328 Override in a subclass to manipulate the request or metadata 

329 before they are sent to the CloudTasks server. 

330 """ 

331 return request, metadata 

332 

333 def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: 

334 """Post-rpc interceptor for get_iam_policy 

335 

336 DEPRECATED. Please use the `post_get_iam_policy_with_metadata` 

337 interceptor instead. 

338 

339 Override in a subclass to read or manipulate the response 

340 after it is returned by the CloudTasks server but before 

341 it is returned to user code. This `post_get_iam_policy` interceptor runs 

342 before the `post_get_iam_policy_with_metadata` interceptor. 

343 """ 

344 return response 

345 

346 def post_get_iam_policy_with_metadata( 

347 self, 

348 response: policy_pb2.Policy, 

349 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

350 ) -> Tuple[policy_pb2.Policy, Sequence[Tuple[str, Union[str, bytes]]]]: 

351 """Post-rpc interceptor for get_iam_policy 

352 

353 Override in a subclass to read or manipulate the response or metadata after it 

354 is returned by the CloudTasks server but before it is returned to user code. 

355 

356 We recommend only using this `post_get_iam_policy_with_metadata` 

357 interceptor in new development instead of the `post_get_iam_policy` interceptor. 

358 When both interceptors are used, this `post_get_iam_policy_with_metadata` interceptor runs after the 

359 `post_get_iam_policy` interceptor. The (possibly modified) response returned by 

360 `post_get_iam_policy` will be passed to 

361 `post_get_iam_policy_with_metadata`. 

362 """ 

363 return response, metadata 

364 

365 def pre_get_queue( 

366 self, 

367 request: cloudtasks.GetQueueRequest, 

368 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

369 ) -> Tuple[cloudtasks.GetQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

370 """Pre-rpc interceptor for get_queue 

371 

372 Override in a subclass to manipulate the request or metadata 

373 before they are sent to the CloudTasks server. 

374 """ 

375 return request, metadata 

376 

377 def post_get_queue(self, response: queue.Queue) -> queue.Queue: 

378 """Post-rpc interceptor for get_queue 

379 

380 DEPRECATED. Please use the `post_get_queue_with_metadata` 

381 interceptor instead. 

382 

383 Override in a subclass to read or manipulate the response 

384 after it is returned by the CloudTasks server but before 

385 it is returned to user code. This `post_get_queue` interceptor runs 

386 before the `post_get_queue_with_metadata` interceptor. 

387 """ 

388 return response 

389 

390 def post_get_queue_with_metadata( 

391 self, response: queue.Queue, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

392 ) -> Tuple[queue.Queue, Sequence[Tuple[str, Union[str, bytes]]]]: 

393 """Post-rpc interceptor for get_queue 

394 

395 Override in a subclass to read or manipulate the response or metadata after it 

396 is returned by the CloudTasks server but before it is returned to user code. 

397 

398 We recommend only using this `post_get_queue_with_metadata` 

399 interceptor in new development instead of the `post_get_queue` interceptor. 

400 When both interceptors are used, this `post_get_queue_with_metadata` interceptor runs after the 

401 `post_get_queue` interceptor. The (possibly modified) response returned by 

402 `post_get_queue` will be passed to 

403 `post_get_queue_with_metadata`. 

404 """ 

405 return response, metadata 

406 

407 def pre_get_task( 

408 self, 

409 request: cloudtasks.GetTaskRequest, 

410 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

411 ) -> Tuple[cloudtasks.GetTaskRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

412 """Pre-rpc interceptor for get_task 

413 

414 Override in a subclass to manipulate the request or metadata 

415 before they are sent to the CloudTasks server. 

416 """ 

417 return request, metadata 

418 

419 def post_get_task(self, response: task.Task) -> task.Task: 

420 """Post-rpc interceptor for get_task 

421 

422 DEPRECATED. Please use the `post_get_task_with_metadata` 

423 interceptor instead. 

424 

425 Override in a subclass to read or manipulate the response 

426 after it is returned by the CloudTasks server but before 

427 it is returned to user code. This `post_get_task` interceptor runs 

428 before the `post_get_task_with_metadata` interceptor. 

429 """ 

430 return response 

431 

432 def post_get_task_with_metadata( 

433 self, response: task.Task, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

434 ) -> Tuple[task.Task, Sequence[Tuple[str, Union[str, bytes]]]]: 

435 """Post-rpc interceptor for get_task 

436 

437 Override in a subclass to read or manipulate the response or metadata after it 

438 is returned by the CloudTasks server but before it is returned to user code. 

439 

440 We recommend only using this `post_get_task_with_metadata` 

441 interceptor in new development instead of the `post_get_task` interceptor. 

442 When both interceptors are used, this `post_get_task_with_metadata` interceptor runs after the 

443 `post_get_task` interceptor. The (possibly modified) response returned by 

444 `post_get_task` will be passed to 

445 `post_get_task_with_metadata`. 

446 """ 

447 return response, metadata 

448 

449 def pre_list_queues( 

450 self, 

451 request: cloudtasks.ListQueuesRequest, 

452 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

453 ) -> Tuple[cloudtasks.ListQueuesRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

454 """Pre-rpc interceptor for list_queues 

455 

456 Override in a subclass to manipulate the request or metadata 

457 before they are sent to the CloudTasks server. 

458 """ 

459 return request, metadata 

460 

461 def post_list_queues( 

462 self, response: cloudtasks.ListQueuesResponse 

463 ) -> cloudtasks.ListQueuesResponse: 

464 """Post-rpc interceptor for list_queues 

465 

466 DEPRECATED. Please use the `post_list_queues_with_metadata` 

467 interceptor instead. 

468 

469 Override in a subclass to read or manipulate the response 

470 after it is returned by the CloudTasks server but before 

471 it is returned to user code. This `post_list_queues` interceptor runs 

472 before the `post_list_queues_with_metadata` interceptor. 

473 """ 

474 return response 

475 

476 def post_list_queues_with_metadata( 

477 self, 

478 response: cloudtasks.ListQueuesResponse, 

479 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

480 ) -> Tuple[cloudtasks.ListQueuesResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

481 """Post-rpc interceptor for list_queues 

482 

483 Override in a subclass to read or manipulate the response or metadata after it 

484 is returned by the CloudTasks server but before it is returned to user code. 

485 

486 We recommend only using this `post_list_queues_with_metadata` 

487 interceptor in new development instead of the `post_list_queues` interceptor. 

488 When both interceptors are used, this `post_list_queues_with_metadata` interceptor runs after the 

489 `post_list_queues` interceptor. The (possibly modified) response returned by 

490 `post_list_queues` will be passed to 

491 `post_list_queues_with_metadata`. 

492 """ 

493 return response, metadata 

494 

495 def pre_list_tasks( 

496 self, 

497 request: cloudtasks.ListTasksRequest, 

498 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

499 ) -> Tuple[cloudtasks.ListTasksRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

500 """Pre-rpc interceptor for list_tasks 

501 

502 Override in a subclass to manipulate the request or metadata 

503 before they are sent to the CloudTasks server. 

504 """ 

505 return request, metadata 

506 

507 def post_list_tasks( 

508 self, response: cloudtasks.ListTasksResponse 

509 ) -> cloudtasks.ListTasksResponse: 

510 """Post-rpc interceptor for list_tasks 

511 

512 DEPRECATED. Please use the `post_list_tasks_with_metadata` 

513 interceptor instead. 

514 

515 Override in a subclass to read or manipulate the response 

516 after it is returned by the CloudTasks server but before 

517 it is returned to user code. This `post_list_tasks` interceptor runs 

518 before the `post_list_tasks_with_metadata` interceptor. 

519 """ 

520 return response 

521 

522 def post_list_tasks_with_metadata( 

523 self, 

524 response: cloudtasks.ListTasksResponse, 

525 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

526 ) -> Tuple[cloudtasks.ListTasksResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

527 """Post-rpc interceptor for list_tasks 

528 

529 Override in a subclass to read or manipulate the response or metadata after it 

530 is returned by the CloudTasks server but before it is returned to user code. 

531 

532 We recommend only using this `post_list_tasks_with_metadata` 

533 interceptor in new development instead of the `post_list_tasks` interceptor. 

534 When both interceptors are used, this `post_list_tasks_with_metadata` interceptor runs after the 

535 `post_list_tasks` interceptor. The (possibly modified) response returned by 

536 `post_list_tasks` will be passed to 

537 `post_list_tasks_with_metadata`. 

538 """ 

539 return response, metadata 

540 

541 def pre_pause_queue( 

542 self, 

543 request: cloudtasks.PauseQueueRequest, 

544 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

545 ) -> Tuple[cloudtasks.PauseQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

546 """Pre-rpc interceptor for pause_queue 

547 

548 Override in a subclass to manipulate the request or metadata 

549 before they are sent to the CloudTasks server. 

550 """ 

551 return request, metadata 

552 

553 def post_pause_queue(self, response: queue.Queue) -> queue.Queue: 

554 """Post-rpc interceptor for pause_queue 

555 

556 DEPRECATED. Please use the `post_pause_queue_with_metadata` 

557 interceptor instead. 

558 

559 Override in a subclass to read or manipulate the response 

560 after it is returned by the CloudTasks server but before 

561 it is returned to user code. This `post_pause_queue` interceptor runs 

562 before the `post_pause_queue_with_metadata` interceptor. 

563 """ 

564 return response 

565 

566 def post_pause_queue_with_metadata( 

567 self, response: queue.Queue, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

568 ) -> Tuple[queue.Queue, Sequence[Tuple[str, Union[str, bytes]]]]: 

569 """Post-rpc interceptor for pause_queue 

570 

571 Override in a subclass to read or manipulate the response or metadata after it 

572 is returned by the CloudTasks server but before it is returned to user code. 

573 

574 We recommend only using this `post_pause_queue_with_metadata` 

575 interceptor in new development instead of the `post_pause_queue` interceptor. 

576 When both interceptors are used, this `post_pause_queue_with_metadata` interceptor runs after the 

577 `post_pause_queue` interceptor. The (possibly modified) response returned by 

578 `post_pause_queue` will be passed to 

579 `post_pause_queue_with_metadata`. 

580 """ 

581 return response, metadata 

582 

583 def pre_purge_queue( 

584 self, 

585 request: cloudtasks.PurgeQueueRequest, 

586 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

587 ) -> Tuple[cloudtasks.PurgeQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

588 """Pre-rpc interceptor for purge_queue 

589 

590 Override in a subclass to manipulate the request or metadata 

591 before they are sent to the CloudTasks server. 

592 """ 

593 return request, metadata 

594 

595 def post_purge_queue(self, response: queue.Queue) -> queue.Queue: 

596 """Post-rpc interceptor for purge_queue 

597 

598 DEPRECATED. Please use the `post_purge_queue_with_metadata` 

599 interceptor instead. 

600 

601 Override in a subclass to read or manipulate the response 

602 after it is returned by the CloudTasks server but before 

603 it is returned to user code. This `post_purge_queue` interceptor runs 

604 before the `post_purge_queue_with_metadata` interceptor. 

605 """ 

606 return response 

607 

608 def post_purge_queue_with_metadata( 

609 self, response: queue.Queue, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

610 ) -> Tuple[queue.Queue, Sequence[Tuple[str, Union[str, bytes]]]]: 

611 """Post-rpc interceptor for purge_queue 

612 

613 Override in a subclass to read or manipulate the response or metadata after it 

614 is returned by the CloudTasks server but before it is returned to user code. 

615 

616 We recommend only using this `post_purge_queue_with_metadata` 

617 interceptor in new development instead of the `post_purge_queue` interceptor. 

618 When both interceptors are used, this `post_purge_queue_with_metadata` interceptor runs after the 

619 `post_purge_queue` interceptor. The (possibly modified) response returned by 

620 `post_purge_queue` will be passed to 

621 `post_purge_queue_with_metadata`. 

622 """ 

623 return response, metadata 

624 

625 def pre_resume_queue( 

626 self, 

627 request: cloudtasks.ResumeQueueRequest, 

628 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

629 ) -> Tuple[cloudtasks.ResumeQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

630 """Pre-rpc interceptor for resume_queue 

631 

632 Override in a subclass to manipulate the request or metadata 

633 before they are sent to the CloudTasks server. 

634 """ 

635 return request, metadata 

636 

637 def post_resume_queue(self, response: queue.Queue) -> queue.Queue: 

638 """Post-rpc interceptor for resume_queue 

639 

640 DEPRECATED. Please use the `post_resume_queue_with_metadata` 

641 interceptor instead. 

642 

643 Override in a subclass to read or manipulate the response 

644 after it is returned by the CloudTasks server but before 

645 it is returned to user code. This `post_resume_queue` interceptor runs 

646 before the `post_resume_queue_with_metadata` interceptor. 

647 """ 

648 return response 

649 

650 def post_resume_queue_with_metadata( 

651 self, response: queue.Queue, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

652 ) -> Tuple[queue.Queue, Sequence[Tuple[str, Union[str, bytes]]]]: 

653 """Post-rpc interceptor for resume_queue 

654 

655 Override in a subclass to read or manipulate the response or metadata after it 

656 is returned by the CloudTasks server but before it is returned to user code. 

657 

658 We recommend only using this `post_resume_queue_with_metadata` 

659 interceptor in new development instead of the `post_resume_queue` interceptor. 

660 When both interceptors are used, this `post_resume_queue_with_metadata` interceptor runs after the 

661 `post_resume_queue` interceptor. The (possibly modified) response returned by 

662 `post_resume_queue` will be passed to 

663 `post_resume_queue_with_metadata`. 

664 """ 

665 return response, metadata 

666 

667 def pre_run_task( 

668 self, 

669 request: cloudtasks.RunTaskRequest, 

670 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

671 ) -> Tuple[cloudtasks.RunTaskRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

672 """Pre-rpc interceptor for run_task 

673 

674 Override in a subclass to manipulate the request or metadata 

675 before they are sent to the CloudTasks server. 

676 """ 

677 return request, metadata 

678 

679 def post_run_task(self, response: task.Task) -> task.Task: 

680 """Post-rpc interceptor for run_task 

681 

682 DEPRECATED. Please use the `post_run_task_with_metadata` 

683 interceptor instead. 

684 

685 Override in a subclass to read or manipulate the response 

686 after it is returned by the CloudTasks server but before 

687 it is returned to user code. This `post_run_task` interceptor runs 

688 before the `post_run_task_with_metadata` interceptor. 

689 """ 

690 return response 

691 

692 def post_run_task_with_metadata( 

693 self, response: task.Task, metadata: Sequence[Tuple[str, Union[str, bytes]]] 

694 ) -> Tuple[task.Task, Sequence[Tuple[str, Union[str, bytes]]]]: 

695 """Post-rpc interceptor for run_task 

696 

697 Override in a subclass to read or manipulate the response or metadata after it 

698 is returned by the CloudTasks server but before it is returned to user code. 

699 

700 We recommend only using this `post_run_task_with_metadata` 

701 interceptor in new development instead of the `post_run_task` interceptor. 

702 When both interceptors are used, this `post_run_task_with_metadata` interceptor runs after the 

703 `post_run_task` interceptor. The (possibly modified) response returned by 

704 `post_run_task` will be passed to 

705 `post_run_task_with_metadata`. 

706 """ 

707 return response, metadata 

708 

709 def pre_set_iam_policy( 

710 self, 

711 request: iam_policy_pb2.SetIamPolicyRequest, 

712 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

713 ) -> Tuple[ 

714 iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] 

715 ]: 

716 """Pre-rpc interceptor for set_iam_policy 

717 

718 Override in a subclass to manipulate the request or metadata 

719 before they are sent to the CloudTasks server. 

720 """ 

721 return request, metadata 

722 

723 def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: 

724 """Post-rpc interceptor for set_iam_policy 

725 

726 DEPRECATED. Please use the `post_set_iam_policy_with_metadata` 

727 interceptor instead. 

728 

729 Override in a subclass to read or manipulate the response 

730 after it is returned by the CloudTasks server but before 

731 it is returned to user code. This `post_set_iam_policy` interceptor runs 

732 before the `post_set_iam_policy_with_metadata` interceptor. 

733 """ 

734 return response 

735 

736 def post_set_iam_policy_with_metadata( 

737 self, 

738 response: policy_pb2.Policy, 

739 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

740 ) -> Tuple[policy_pb2.Policy, Sequence[Tuple[str, Union[str, bytes]]]]: 

741 """Post-rpc interceptor for set_iam_policy 

742 

743 Override in a subclass to read or manipulate the response or metadata after it 

744 is returned by the CloudTasks server but before it is returned to user code. 

745 

746 We recommend only using this `post_set_iam_policy_with_metadata` 

747 interceptor in new development instead of the `post_set_iam_policy` interceptor. 

748 When both interceptors are used, this `post_set_iam_policy_with_metadata` interceptor runs after the 

749 `post_set_iam_policy` interceptor. The (possibly modified) response returned by 

750 `post_set_iam_policy` will be passed to 

751 `post_set_iam_policy_with_metadata`. 

752 """ 

753 return response, metadata 

754 

755 def pre_test_iam_permissions( 

756 self, 

757 request: iam_policy_pb2.TestIamPermissionsRequest, 

758 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

759 ) -> Tuple[ 

760 iam_policy_pb2.TestIamPermissionsRequest, 

761 Sequence[Tuple[str, Union[str, bytes]]], 

762 ]: 

763 """Pre-rpc interceptor for test_iam_permissions 

764 

765 Override in a subclass to manipulate the request or metadata 

766 before they are sent to the CloudTasks server. 

767 """ 

768 return request, metadata 

769 

770 def post_test_iam_permissions( 

771 self, response: iam_policy_pb2.TestIamPermissionsResponse 

772 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

773 """Post-rpc interceptor for test_iam_permissions 

774 

775 DEPRECATED. Please use the `post_test_iam_permissions_with_metadata` 

776 interceptor instead. 

777 

778 Override in a subclass to read or manipulate the response 

779 after it is returned by the CloudTasks server but before 

780 it is returned to user code. This `post_test_iam_permissions` interceptor runs 

781 before the `post_test_iam_permissions_with_metadata` interceptor. 

782 """ 

783 return response 

784 

785 def post_test_iam_permissions_with_metadata( 

786 self, 

787 response: iam_policy_pb2.TestIamPermissionsResponse, 

788 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

789 ) -> Tuple[ 

790 iam_policy_pb2.TestIamPermissionsResponse, 

791 Sequence[Tuple[str, Union[str, bytes]]], 

792 ]: 

793 """Post-rpc interceptor for test_iam_permissions 

794 

795 Override in a subclass to read or manipulate the response or metadata after it 

796 is returned by the CloudTasks server but before it is returned to user code. 

797 

798 We recommend only using this `post_test_iam_permissions_with_metadata` 

799 interceptor in new development instead of the `post_test_iam_permissions` interceptor. 

800 When both interceptors are used, this `post_test_iam_permissions_with_metadata` interceptor runs after the 

801 `post_test_iam_permissions` interceptor. The (possibly modified) response returned by 

802 `post_test_iam_permissions` will be passed to 

803 `post_test_iam_permissions_with_metadata`. 

804 """ 

805 return response, metadata 

806 

807 def pre_update_queue( 

808 self, 

809 request: cloudtasks.UpdateQueueRequest, 

810 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

811 ) -> Tuple[cloudtasks.UpdateQueueRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

812 """Pre-rpc interceptor for update_queue 

813 

814 Override in a subclass to manipulate the request or metadata 

815 before they are sent to the CloudTasks server. 

816 """ 

817 return request, metadata 

818 

819 def post_update_queue(self, response: gct_queue.Queue) -> gct_queue.Queue: 

820 """Post-rpc interceptor for update_queue 

821 

822 DEPRECATED. Please use the `post_update_queue_with_metadata` 

823 interceptor instead. 

824 

825 Override in a subclass to read or manipulate the response 

826 after it is returned by the CloudTasks server but before 

827 it is returned to user code. This `post_update_queue` interceptor runs 

828 before the `post_update_queue_with_metadata` interceptor. 

829 """ 

830 return response 

831 

832 def post_update_queue_with_metadata( 

833 self, 

834 response: gct_queue.Queue, 

835 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

836 ) -> Tuple[gct_queue.Queue, Sequence[Tuple[str, Union[str, bytes]]]]: 

837 """Post-rpc interceptor for update_queue 

838 

839 Override in a subclass to read or manipulate the response or metadata after it 

840 is returned by the CloudTasks server but before it is returned to user code. 

841 

842 We recommend only using this `post_update_queue_with_metadata` 

843 interceptor in new development instead of the `post_update_queue` interceptor. 

844 When both interceptors are used, this `post_update_queue_with_metadata` interceptor runs after the 

845 `post_update_queue` interceptor. The (possibly modified) response returned by 

846 `post_update_queue` will be passed to 

847 `post_update_queue_with_metadata`. 

848 """ 

849 return response, metadata 

850 

851 def pre_get_location( 

852 self, 

853 request: locations_pb2.GetLocationRequest, 

854 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

855 ) -> Tuple[ 

856 locations_pb2.GetLocationRequest, Sequence[Tuple[str, Union[str, bytes]]] 

857 ]: 

858 """Pre-rpc interceptor for get_location 

859 

860 Override in a subclass to manipulate the request or metadata 

861 before they are sent to the CloudTasks server. 

862 """ 

863 return request, metadata 

864 

865 def post_get_location( 

866 self, response: locations_pb2.Location 

867 ) -> locations_pb2.Location: 

868 """Post-rpc interceptor for get_location 

869 

870 Override in a subclass to manipulate the response 

871 after it is returned by the CloudTasks server but before 

872 it is returned to user code. 

873 """ 

874 return response 

875 

876 def pre_list_locations( 

877 self, 

878 request: locations_pb2.ListLocationsRequest, 

879 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

880 ) -> Tuple[ 

881 locations_pb2.ListLocationsRequest, Sequence[Tuple[str, Union[str, bytes]]] 

882 ]: 

883 """Pre-rpc interceptor for list_locations 

884 

885 Override in a subclass to manipulate the request or metadata 

886 before they are sent to the CloudTasks server. 

887 """ 

888 return request, metadata 

889 

890 def post_list_locations( 

891 self, response: locations_pb2.ListLocationsResponse 

892 ) -> locations_pb2.ListLocationsResponse: 

893 """Post-rpc interceptor for list_locations 

894 

895 Override in a subclass to manipulate the response 

896 after it is returned by the CloudTasks server but before 

897 it is returned to user code. 

898 """ 

899 return response 

900 

901 

902@dataclasses.dataclass 

903class CloudTasksRestStub: 

904 _session: AuthorizedSession 

905 _host: str 

906 _interceptor: CloudTasksRestInterceptor 

907 

908 

909class CloudTasksRestTransport(_BaseCloudTasksRestTransport): 

910 """REST backend synchronous transport for CloudTasks. 

911 

912 Cloud Tasks allows developers to manage the execution of 

913 background work in their applications. 

914 

915 This class defines the same methods as the primary client, so the 

916 primary client can load the underlying transport implementation 

917 and call it. 

918 

919 It sends JSON representations of protocol buffers over HTTP/1.1 

920 """ 

921 

922 def __init__( 

923 self, 

924 *, 

925 host: str = "cloudtasks.googleapis.com", 

926 credentials: Optional[ga_credentials.Credentials] = None, 

927 credentials_file: Optional[str] = None, 

928 scopes: Optional[Sequence[str]] = None, 

929 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

930 quota_project_id: Optional[str] = None, 

931 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

932 always_use_jwt_access: Optional[bool] = False, 

933 url_scheme: str = "https", 

934 interceptor: Optional[CloudTasksRestInterceptor] = None, 

935 api_audience: Optional[str] = None, 

936 ) -> None: 

937 """Instantiate the transport. 

938 

939 Args: 

940 host (Optional[str]): 

941 The hostname to connect to (default: 'cloudtasks.googleapis.com'). 

942 credentials (Optional[google.auth.credentials.Credentials]): The 

943 authorization credentials to attach to requests. These 

944 credentials identify the application to the service; if none 

945 are specified, the client will attempt to ascertain the 

946 credentials from the environment. 

947 

948 credentials_file (Optional[str]): A file with credentials that can 

949 be loaded with :func:`google.auth.load_credentials_from_file`. 

950 This argument is ignored if ``channel`` is provided. 

951 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

952 ignored if ``channel`` is provided. 

953 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client 

954 certificate to configure mutual TLS HTTP channel. It is ignored 

955 if ``channel`` is provided. 

956 quota_project_id (Optional[str]): An optional project to use for billing 

957 and quota. 

958 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

959 The client info used to send a user-agent string along with 

960 API requests. If ``None``, then default info will be used. 

961 Generally, you only need to set this if you are developing 

962 your own client library. 

963 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

964 be used for service account credentials. 

965 url_scheme: the protocol scheme for the API endpoint. Normally 

966 "https", but for testing or local servers, 

967 "http" can be specified. 

968 """ 

969 # Run the base constructor 

970 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. 

971 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the 

972 # credentials object 

973 super().__init__( 

974 host=host, 

975 credentials=credentials, 

976 client_info=client_info, 

977 always_use_jwt_access=always_use_jwt_access, 

978 url_scheme=url_scheme, 

979 api_audience=api_audience, 

980 ) 

981 self._session = AuthorizedSession( 

982 self._credentials, default_host=self.DEFAULT_HOST 

983 ) 

984 if client_cert_source_for_mtls: 

985 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

986 self._interceptor = interceptor or CloudTasksRestInterceptor() 

987 self._prep_wrapped_messages(client_info) 

988 

989 class _CreateQueue( 

990 _BaseCloudTasksRestTransport._BaseCreateQueue, CloudTasksRestStub 

991 ): 

992 def __hash__(self): 

993 return hash("CloudTasksRestTransport.CreateQueue") 

994 

995 @staticmethod 

996 def _get_response( 

997 host, 

998 metadata, 

999 query_params, 

1000 session, 

1001 timeout, 

1002 transcoded_request, 

1003 body=None, 

1004 ): 

1005 uri = transcoded_request["uri"] 

1006 method = transcoded_request["method"] 

1007 headers = dict(metadata) 

1008 headers["Content-Type"] = "application/json" 

1009 response = getattr(session, method)( 

1010 "{host}{uri}".format(host=host, uri=uri), 

1011 timeout=timeout, 

1012 headers=headers, 

1013 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1014 data=body, 

1015 ) 

1016 return response 

1017 

1018 def __call__( 

1019 self, 

1020 request: cloudtasks.CreateQueueRequest, 

1021 *, 

1022 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1023 timeout: Optional[float] = None, 

1024 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1025 ) -> gct_queue.Queue: 

1026 r"""Call the create queue method over HTTP. 

1027 

1028 Args: 

1029 request (~.cloudtasks.CreateQueueRequest): 

1030 The request object. Request message for 

1031 [CreateQueue][google.cloud.tasks.v2.CloudTasks.CreateQueue]. 

1032 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1033 should be retried. 

1034 timeout (float): The timeout for this request. 

1035 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1036 sent along with the request as metadata. Normally, each value must be of type `str`, 

1037 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1038 be of type `bytes`. 

1039 

1040 Returns: 

1041 ~.gct_queue.Queue: 

1042 A queue is a container of related 

1043 tasks. Queues are configured to manage 

1044 how those tasks are dispatched. 

1045 Configurable properties include rate 

1046 limits, retry options, queue types, and 

1047 others. 

1048 

1049 """ 

1050 

1051 http_options = ( 

1052 _BaseCloudTasksRestTransport._BaseCreateQueue._get_http_options() 

1053 ) 

1054 

1055 request, metadata = self._interceptor.pre_create_queue(request, metadata) 

1056 transcoded_request = ( 

1057 _BaseCloudTasksRestTransport._BaseCreateQueue._get_transcoded_request( 

1058 http_options, request 

1059 ) 

1060 ) 

1061 

1062 body = _BaseCloudTasksRestTransport._BaseCreateQueue._get_request_body_json( 

1063 transcoded_request 

1064 ) 

1065 

1066 # Jsonify the query params 

1067 query_params = ( 

1068 _BaseCloudTasksRestTransport._BaseCreateQueue._get_query_params_json( 

1069 transcoded_request 

1070 ) 

1071 ) 

1072 

1073 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1074 logging.DEBUG 

1075 ): # pragma: NO COVER 

1076 request_url = "{host}{uri}".format( 

1077 host=self._host, uri=transcoded_request["uri"] 

1078 ) 

1079 method = transcoded_request["method"] 

1080 try: 

1081 request_payload = type(request).to_json(request) 

1082 except: 

1083 request_payload = None 

1084 http_request = { 

1085 "payload": request_payload, 

1086 "requestMethod": method, 

1087 "requestUrl": request_url, 

1088 "headers": dict(metadata), 

1089 } 

1090 _LOGGER.debug( 

1091 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.CreateQueue", 

1092 extra={ 

1093 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1094 "rpcName": "CreateQueue", 

1095 "httpRequest": http_request, 

1096 "metadata": http_request["headers"], 

1097 }, 

1098 ) 

1099 

1100 # Send the request 

1101 response = CloudTasksRestTransport._CreateQueue._get_response( 

1102 self._host, 

1103 metadata, 

1104 query_params, 

1105 self._session, 

1106 timeout, 

1107 transcoded_request, 

1108 body, 

1109 ) 

1110 

1111 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1112 # subclass. 

1113 if response.status_code >= 400: 

1114 raise core_exceptions.from_http_response(response) 

1115 

1116 # Return the response 

1117 resp = gct_queue.Queue() 

1118 pb_resp = gct_queue.Queue.pb(resp) 

1119 

1120 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1121 

1122 resp = self._interceptor.post_create_queue(resp) 

1123 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1124 resp, _ = self._interceptor.post_create_queue_with_metadata( 

1125 resp, response_metadata 

1126 ) 

1127 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1128 logging.DEBUG 

1129 ): # pragma: NO COVER 

1130 try: 

1131 response_payload = gct_queue.Queue.to_json(response) 

1132 except: 

1133 response_payload = None 

1134 http_response = { 

1135 "payload": response_payload, 

1136 "headers": dict(response.headers), 

1137 "status": response.status_code, 

1138 } 

1139 _LOGGER.debug( 

1140 "Received response for google.cloud.tasks_v2.CloudTasksClient.create_queue", 

1141 extra={ 

1142 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1143 "rpcName": "CreateQueue", 

1144 "metadata": http_response["headers"], 

1145 "httpResponse": http_response, 

1146 }, 

1147 ) 

1148 return resp 

1149 

1150 class _CreateTask(_BaseCloudTasksRestTransport._BaseCreateTask, CloudTasksRestStub): 

1151 def __hash__(self): 

1152 return hash("CloudTasksRestTransport.CreateTask") 

1153 

1154 @staticmethod 

1155 def _get_response( 

1156 host, 

1157 metadata, 

1158 query_params, 

1159 session, 

1160 timeout, 

1161 transcoded_request, 

1162 body=None, 

1163 ): 

1164 uri = transcoded_request["uri"] 

1165 method = transcoded_request["method"] 

1166 headers = dict(metadata) 

1167 headers["Content-Type"] = "application/json" 

1168 response = getattr(session, method)( 

1169 "{host}{uri}".format(host=host, uri=uri), 

1170 timeout=timeout, 

1171 headers=headers, 

1172 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1173 data=body, 

1174 ) 

1175 return response 

1176 

1177 def __call__( 

1178 self, 

1179 request: cloudtasks.CreateTaskRequest, 

1180 *, 

1181 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1182 timeout: Optional[float] = None, 

1183 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1184 ) -> gct_task.Task: 

1185 r"""Call the create task method over HTTP. 

1186 

1187 Args: 

1188 request (~.cloudtasks.CreateTaskRequest): 

1189 The request object. Request message for 

1190 [CreateTask][google.cloud.tasks.v2.CloudTasks.CreateTask]. 

1191 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1192 should be retried. 

1193 timeout (float): The timeout for this request. 

1194 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1195 sent along with the request as metadata. Normally, each value must be of type `str`, 

1196 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1197 be of type `bytes`. 

1198 

1199 Returns: 

1200 ~.gct_task.Task: 

1201 A unit of scheduled work. 

1202 """ 

1203 

1204 http_options = ( 

1205 _BaseCloudTasksRestTransport._BaseCreateTask._get_http_options() 

1206 ) 

1207 

1208 request, metadata = self._interceptor.pre_create_task(request, metadata) 

1209 transcoded_request = ( 

1210 _BaseCloudTasksRestTransport._BaseCreateTask._get_transcoded_request( 

1211 http_options, request 

1212 ) 

1213 ) 

1214 

1215 body = _BaseCloudTasksRestTransport._BaseCreateTask._get_request_body_json( 

1216 transcoded_request 

1217 ) 

1218 

1219 # Jsonify the query params 

1220 query_params = ( 

1221 _BaseCloudTasksRestTransport._BaseCreateTask._get_query_params_json( 

1222 transcoded_request 

1223 ) 

1224 ) 

1225 

1226 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1227 logging.DEBUG 

1228 ): # pragma: NO COVER 

1229 request_url = "{host}{uri}".format( 

1230 host=self._host, uri=transcoded_request["uri"] 

1231 ) 

1232 method = transcoded_request["method"] 

1233 try: 

1234 request_payload = type(request).to_json(request) 

1235 except: 

1236 request_payload = None 

1237 http_request = { 

1238 "payload": request_payload, 

1239 "requestMethod": method, 

1240 "requestUrl": request_url, 

1241 "headers": dict(metadata), 

1242 } 

1243 _LOGGER.debug( 

1244 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.CreateTask", 

1245 extra={ 

1246 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1247 "rpcName": "CreateTask", 

1248 "httpRequest": http_request, 

1249 "metadata": http_request["headers"], 

1250 }, 

1251 ) 

1252 

1253 # Send the request 

1254 response = CloudTasksRestTransport._CreateTask._get_response( 

1255 self._host, 

1256 metadata, 

1257 query_params, 

1258 self._session, 

1259 timeout, 

1260 transcoded_request, 

1261 body, 

1262 ) 

1263 

1264 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1265 # subclass. 

1266 if response.status_code >= 400: 

1267 raise core_exceptions.from_http_response(response) 

1268 

1269 # Return the response 

1270 resp = gct_task.Task() 

1271 pb_resp = gct_task.Task.pb(resp) 

1272 

1273 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1274 

1275 resp = self._interceptor.post_create_task(resp) 

1276 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1277 resp, _ = self._interceptor.post_create_task_with_metadata( 

1278 resp, response_metadata 

1279 ) 

1280 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1281 logging.DEBUG 

1282 ): # pragma: NO COVER 

1283 try: 

1284 response_payload = gct_task.Task.to_json(response) 

1285 except: 

1286 response_payload = None 

1287 http_response = { 

1288 "payload": response_payload, 

1289 "headers": dict(response.headers), 

1290 "status": response.status_code, 

1291 } 

1292 _LOGGER.debug( 

1293 "Received response for google.cloud.tasks_v2.CloudTasksClient.create_task", 

1294 extra={ 

1295 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1296 "rpcName": "CreateTask", 

1297 "metadata": http_response["headers"], 

1298 "httpResponse": http_response, 

1299 }, 

1300 ) 

1301 return resp 

1302 

1303 class _DeleteQueue( 

1304 _BaseCloudTasksRestTransport._BaseDeleteQueue, CloudTasksRestStub 

1305 ): 

1306 def __hash__(self): 

1307 return hash("CloudTasksRestTransport.DeleteQueue") 

1308 

1309 @staticmethod 

1310 def _get_response( 

1311 host, 

1312 metadata, 

1313 query_params, 

1314 session, 

1315 timeout, 

1316 transcoded_request, 

1317 body=None, 

1318 ): 

1319 uri = transcoded_request["uri"] 

1320 method = transcoded_request["method"] 

1321 headers = dict(metadata) 

1322 headers["Content-Type"] = "application/json" 

1323 response = getattr(session, method)( 

1324 "{host}{uri}".format(host=host, uri=uri), 

1325 timeout=timeout, 

1326 headers=headers, 

1327 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1328 ) 

1329 return response 

1330 

1331 def __call__( 

1332 self, 

1333 request: cloudtasks.DeleteQueueRequest, 

1334 *, 

1335 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1336 timeout: Optional[float] = None, 

1337 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1338 ): 

1339 r"""Call the delete queue method over HTTP. 

1340 

1341 Args: 

1342 request (~.cloudtasks.DeleteQueueRequest): 

1343 The request object. Request message for 

1344 [DeleteQueue][google.cloud.tasks.v2.CloudTasks.DeleteQueue]. 

1345 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1346 should be retried. 

1347 timeout (float): The timeout for this request. 

1348 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1349 sent along with the request as metadata. Normally, each value must be of type `str`, 

1350 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1351 be of type `bytes`. 

1352 """ 

1353 

1354 http_options = ( 

1355 _BaseCloudTasksRestTransport._BaseDeleteQueue._get_http_options() 

1356 ) 

1357 

1358 request, metadata = self._interceptor.pre_delete_queue(request, metadata) 

1359 transcoded_request = ( 

1360 _BaseCloudTasksRestTransport._BaseDeleteQueue._get_transcoded_request( 

1361 http_options, request 

1362 ) 

1363 ) 

1364 

1365 # Jsonify the query params 

1366 query_params = ( 

1367 _BaseCloudTasksRestTransport._BaseDeleteQueue._get_query_params_json( 

1368 transcoded_request 

1369 ) 

1370 ) 

1371 

1372 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1373 logging.DEBUG 

1374 ): # pragma: NO COVER 

1375 request_url = "{host}{uri}".format( 

1376 host=self._host, uri=transcoded_request["uri"] 

1377 ) 

1378 method = transcoded_request["method"] 

1379 try: 

1380 request_payload = json_format.MessageToJson(request) 

1381 except: 

1382 request_payload = None 

1383 http_request = { 

1384 "payload": request_payload, 

1385 "requestMethod": method, 

1386 "requestUrl": request_url, 

1387 "headers": dict(metadata), 

1388 } 

1389 _LOGGER.debug( 

1390 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.DeleteQueue", 

1391 extra={ 

1392 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1393 "rpcName": "DeleteQueue", 

1394 "httpRequest": http_request, 

1395 "metadata": http_request["headers"], 

1396 }, 

1397 ) 

1398 

1399 # Send the request 

1400 response = CloudTasksRestTransport._DeleteQueue._get_response( 

1401 self._host, 

1402 metadata, 

1403 query_params, 

1404 self._session, 

1405 timeout, 

1406 transcoded_request, 

1407 ) 

1408 

1409 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1410 # subclass. 

1411 if response.status_code >= 400: 

1412 raise core_exceptions.from_http_response(response) 

1413 

1414 class _DeleteTask(_BaseCloudTasksRestTransport._BaseDeleteTask, CloudTasksRestStub): 

1415 def __hash__(self): 

1416 return hash("CloudTasksRestTransport.DeleteTask") 

1417 

1418 @staticmethod 

1419 def _get_response( 

1420 host, 

1421 metadata, 

1422 query_params, 

1423 session, 

1424 timeout, 

1425 transcoded_request, 

1426 body=None, 

1427 ): 

1428 uri = transcoded_request["uri"] 

1429 method = transcoded_request["method"] 

1430 headers = dict(metadata) 

1431 headers["Content-Type"] = "application/json" 

1432 response = getattr(session, method)( 

1433 "{host}{uri}".format(host=host, uri=uri), 

1434 timeout=timeout, 

1435 headers=headers, 

1436 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1437 ) 

1438 return response 

1439 

1440 def __call__( 

1441 self, 

1442 request: cloudtasks.DeleteTaskRequest, 

1443 *, 

1444 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1445 timeout: Optional[float] = None, 

1446 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1447 ): 

1448 r"""Call the delete task method over HTTP. 

1449 

1450 Args: 

1451 request (~.cloudtasks.DeleteTaskRequest): 

1452 The request object. Request message for deleting a task using 

1453 [DeleteTask][google.cloud.tasks.v2.CloudTasks.DeleteTask]. 

1454 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1455 should be retried. 

1456 timeout (float): The timeout for this request. 

1457 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1458 sent along with the request as metadata. Normally, each value must be of type `str`, 

1459 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1460 be of type `bytes`. 

1461 """ 

1462 

1463 http_options = ( 

1464 _BaseCloudTasksRestTransport._BaseDeleteTask._get_http_options() 

1465 ) 

1466 

1467 request, metadata = self._interceptor.pre_delete_task(request, metadata) 

1468 transcoded_request = ( 

1469 _BaseCloudTasksRestTransport._BaseDeleteTask._get_transcoded_request( 

1470 http_options, request 

1471 ) 

1472 ) 

1473 

1474 # Jsonify the query params 

1475 query_params = ( 

1476 _BaseCloudTasksRestTransport._BaseDeleteTask._get_query_params_json( 

1477 transcoded_request 

1478 ) 

1479 ) 

1480 

1481 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1482 logging.DEBUG 

1483 ): # pragma: NO COVER 

1484 request_url = "{host}{uri}".format( 

1485 host=self._host, uri=transcoded_request["uri"] 

1486 ) 

1487 method = transcoded_request["method"] 

1488 try: 

1489 request_payload = json_format.MessageToJson(request) 

1490 except: 

1491 request_payload = None 

1492 http_request = { 

1493 "payload": request_payload, 

1494 "requestMethod": method, 

1495 "requestUrl": request_url, 

1496 "headers": dict(metadata), 

1497 } 

1498 _LOGGER.debug( 

1499 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.DeleteTask", 

1500 extra={ 

1501 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1502 "rpcName": "DeleteTask", 

1503 "httpRequest": http_request, 

1504 "metadata": http_request["headers"], 

1505 }, 

1506 ) 

1507 

1508 # Send the request 

1509 response = CloudTasksRestTransport._DeleteTask._get_response( 

1510 self._host, 

1511 metadata, 

1512 query_params, 

1513 self._session, 

1514 timeout, 

1515 transcoded_request, 

1516 ) 

1517 

1518 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1519 # subclass. 

1520 if response.status_code >= 400: 

1521 raise core_exceptions.from_http_response(response) 

1522 

1523 class _GetIamPolicy( 

1524 _BaseCloudTasksRestTransport._BaseGetIamPolicy, CloudTasksRestStub 

1525 ): 

1526 def __hash__(self): 

1527 return hash("CloudTasksRestTransport.GetIamPolicy") 

1528 

1529 @staticmethod 

1530 def _get_response( 

1531 host, 

1532 metadata, 

1533 query_params, 

1534 session, 

1535 timeout, 

1536 transcoded_request, 

1537 body=None, 

1538 ): 

1539 uri = transcoded_request["uri"] 

1540 method = transcoded_request["method"] 

1541 headers = dict(metadata) 

1542 headers["Content-Type"] = "application/json" 

1543 response = getattr(session, method)( 

1544 "{host}{uri}".format(host=host, uri=uri), 

1545 timeout=timeout, 

1546 headers=headers, 

1547 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1548 data=body, 

1549 ) 

1550 return response 

1551 

1552 def __call__( 

1553 self, 

1554 request: iam_policy_pb2.GetIamPolicyRequest, 

1555 *, 

1556 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1557 timeout: Optional[float] = None, 

1558 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1559 ) -> policy_pb2.Policy: 

1560 r"""Call the get iam policy method over HTTP. 

1561 

1562 Args: 

1563 request (~.iam_policy_pb2.GetIamPolicyRequest): 

1564 The request object. Request message for ``GetIamPolicy`` method. 

1565 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1566 should be retried. 

1567 timeout (float): The timeout for this request. 

1568 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1569 sent along with the request as metadata. Normally, each value must be of type `str`, 

1570 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1571 be of type `bytes`. 

1572 

1573 Returns: 

1574 ~.policy_pb2.Policy: 

1575 An Identity and Access Management (IAM) policy, which 

1576 specifies access controls for Google Cloud resources. 

1577 

1578 A ``Policy`` is a collection of ``bindings``. A 

1579 ``binding`` binds one or more ``members``, or 

1580 principals, to a single ``role``. Principals can be user 

1581 accounts, service accounts, Google groups, and domains 

1582 (such as G Suite). A ``role`` is a named list of 

1583 permissions; each ``role`` can be an IAM predefined role 

1584 or a user-created custom role. 

1585 

1586 For some types of Google Cloud resources, a ``binding`` 

1587 can also specify a ``condition``, which is a logical 

1588 expression that allows access to a resource only if the 

1589 expression evaluates to ``true``. A condition can add 

1590 constraints based on attributes of the request, the 

1591 resource, or both. To learn which resources support 

1592 conditions in their IAM policies, see the `IAM 

1593 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. 

1594 

1595 **JSON example:** 

1596 

1597 :: 

1598 

1599 { 

1600 "bindings": [ 

1601 { 

1602 "role": "roles/resourcemanager.organizationAdmin", 

1603 "members": [ 

1604 "user:mike@example.com", 

1605 "group:admins@example.com", 

1606 "domain:google.com", 

1607 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

1608 ] 

1609 }, 

1610 { 

1611 "role": "roles/resourcemanager.organizationViewer", 

1612 "members": [ 

1613 "user:eve@example.com" 

1614 ], 

1615 "condition": { 

1616 "title": "expirable access", 

1617 "description": "Does not grant access after Sep 2020", 

1618 "expression": "request.time < 

1619 timestamp('2020-10-01T00:00:00.000Z')", 

1620 } 

1621 } 

1622 ], 

1623 "etag": "BwWWja0YfJA=", 

1624 "version": 3 

1625 } 

1626 

1627 **YAML example:** 

1628 

1629 :: 

1630 

1631 bindings: 

1632 - members: 

1633 - user:mike@example.com 

1634 - group:admins@example.com 

1635 - domain:google.com 

1636 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

1637 role: roles/resourcemanager.organizationAdmin 

1638 - members: 

1639 - user:eve@example.com 

1640 role: roles/resourcemanager.organizationViewer 

1641 condition: 

1642 title: expirable access 

1643 description: Does not grant access after Sep 2020 

1644 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

1645 etag: BwWWja0YfJA= 

1646 version: 3 

1647 

1648 For a description of IAM and its features, see the `IAM 

1649 documentation <https://cloud.google.com/iam/docs/>`__. 

1650 

1651 """ 

1652 

1653 http_options = ( 

1654 _BaseCloudTasksRestTransport._BaseGetIamPolicy._get_http_options() 

1655 ) 

1656 

1657 request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) 

1658 transcoded_request = ( 

1659 _BaseCloudTasksRestTransport._BaseGetIamPolicy._get_transcoded_request( 

1660 http_options, request 

1661 ) 

1662 ) 

1663 

1664 body = ( 

1665 _BaseCloudTasksRestTransport._BaseGetIamPolicy._get_request_body_json( 

1666 transcoded_request 

1667 ) 

1668 ) 

1669 

1670 # Jsonify the query params 

1671 query_params = ( 

1672 _BaseCloudTasksRestTransport._BaseGetIamPolicy._get_query_params_json( 

1673 transcoded_request 

1674 ) 

1675 ) 

1676 

1677 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1678 logging.DEBUG 

1679 ): # pragma: NO COVER 

1680 request_url = "{host}{uri}".format( 

1681 host=self._host, uri=transcoded_request["uri"] 

1682 ) 

1683 method = transcoded_request["method"] 

1684 try: 

1685 request_payload = json_format.MessageToJson(request) 

1686 except: 

1687 request_payload = None 

1688 http_request = { 

1689 "payload": request_payload, 

1690 "requestMethod": method, 

1691 "requestUrl": request_url, 

1692 "headers": dict(metadata), 

1693 } 

1694 _LOGGER.debug( 

1695 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.GetIamPolicy", 

1696 extra={ 

1697 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1698 "rpcName": "GetIamPolicy", 

1699 "httpRequest": http_request, 

1700 "metadata": http_request["headers"], 

1701 }, 

1702 ) 

1703 

1704 # Send the request 

1705 response = CloudTasksRestTransport._GetIamPolicy._get_response( 

1706 self._host, 

1707 metadata, 

1708 query_params, 

1709 self._session, 

1710 timeout, 

1711 transcoded_request, 

1712 body, 

1713 ) 

1714 

1715 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1716 # subclass. 

1717 if response.status_code >= 400: 

1718 raise core_exceptions.from_http_response(response) 

1719 

1720 # Return the response 

1721 resp = policy_pb2.Policy() 

1722 pb_resp = resp 

1723 

1724 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1725 

1726 resp = self._interceptor.post_get_iam_policy(resp) 

1727 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1728 resp, _ = self._interceptor.post_get_iam_policy_with_metadata( 

1729 resp, response_metadata 

1730 ) 

1731 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1732 logging.DEBUG 

1733 ): # pragma: NO COVER 

1734 try: 

1735 response_payload = json_format.MessageToJson(resp) 

1736 except: 

1737 response_payload = None 

1738 http_response = { 

1739 "payload": response_payload, 

1740 "headers": dict(response.headers), 

1741 "status": response.status_code, 

1742 } 

1743 _LOGGER.debug( 

1744 "Received response for google.cloud.tasks_v2.CloudTasksClient.get_iam_policy", 

1745 extra={ 

1746 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1747 "rpcName": "GetIamPolicy", 

1748 "metadata": http_response["headers"], 

1749 "httpResponse": http_response, 

1750 }, 

1751 ) 

1752 return resp 

1753 

1754 class _GetQueue(_BaseCloudTasksRestTransport._BaseGetQueue, CloudTasksRestStub): 

1755 def __hash__(self): 

1756 return hash("CloudTasksRestTransport.GetQueue") 

1757 

1758 @staticmethod 

1759 def _get_response( 

1760 host, 

1761 metadata, 

1762 query_params, 

1763 session, 

1764 timeout, 

1765 transcoded_request, 

1766 body=None, 

1767 ): 

1768 uri = transcoded_request["uri"] 

1769 method = transcoded_request["method"] 

1770 headers = dict(metadata) 

1771 headers["Content-Type"] = "application/json" 

1772 response = getattr(session, method)( 

1773 "{host}{uri}".format(host=host, uri=uri), 

1774 timeout=timeout, 

1775 headers=headers, 

1776 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1777 ) 

1778 return response 

1779 

1780 def __call__( 

1781 self, 

1782 request: cloudtasks.GetQueueRequest, 

1783 *, 

1784 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1785 timeout: Optional[float] = None, 

1786 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1787 ) -> queue.Queue: 

1788 r"""Call the get queue method over HTTP. 

1789 

1790 Args: 

1791 request (~.cloudtasks.GetQueueRequest): 

1792 The request object. Request message for 

1793 [GetQueue][google.cloud.tasks.v2.CloudTasks.GetQueue]. 

1794 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1795 should be retried. 

1796 timeout (float): The timeout for this request. 

1797 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1798 sent along with the request as metadata. Normally, each value must be of type `str`, 

1799 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1800 be of type `bytes`. 

1801 

1802 Returns: 

1803 ~.queue.Queue: 

1804 A queue is a container of related 

1805 tasks. Queues are configured to manage 

1806 how those tasks are dispatched. 

1807 Configurable properties include rate 

1808 limits, retry options, queue types, and 

1809 others. 

1810 

1811 """ 

1812 

1813 http_options = ( 

1814 _BaseCloudTasksRestTransport._BaseGetQueue._get_http_options() 

1815 ) 

1816 

1817 request, metadata = self._interceptor.pre_get_queue(request, metadata) 

1818 transcoded_request = ( 

1819 _BaseCloudTasksRestTransport._BaseGetQueue._get_transcoded_request( 

1820 http_options, request 

1821 ) 

1822 ) 

1823 

1824 # Jsonify the query params 

1825 query_params = ( 

1826 _BaseCloudTasksRestTransport._BaseGetQueue._get_query_params_json( 

1827 transcoded_request 

1828 ) 

1829 ) 

1830 

1831 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1832 logging.DEBUG 

1833 ): # pragma: NO COVER 

1834 request_url = "{host}{uri}".format( 

1835 host=self._host, uri=transcoded_request["uri"] 

1836 ) 

1837 method = transcoded_request["method"] 

1838 try: 

1839 request_payload = type(request).to_json(request) 

1840 except: 

1841 request_payload = None 

1842 http_request = { 

1843 "payload": request_payload, 

1844 "requestMethod": method, 

1845 "requestUrl": request_url, 

1846 "headers": dict(metadata), 

1847 } 

1848 _LOGGER.debug( 

1849 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.GetQueue", 

1850 extra={ 

1851 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1852 "rpcName": "GetQueue", 

1853 "httpRequest": http_request, 

1854 "metadata": http_request["headers"], 

1855 }, 

1856 ) 

1857 

1858 # Send the request 

1859 response = CloudTasksRestTransport._GetQueue._get_response( 

1860 self._host, 

1861 metadata, 

1862 query_params, 

1863 self._session, 

1864 timeout, 

1865 transcoded_request, 

1866 ) 

1867 

1868 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1869 # subclass. 

1870 if response.status_code >= 400: 

1871 raise core_exceptions.from_http_response(response) 

1872 

1873 # Return the response 

1874 resp = queue.Queue() 

1875 pb_resp = queue.Queue.pb(resp) 

1876 

1877 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1878 

1879 resp = self._interceptor.post_get_queue(resp) 

1880 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1881 resp, _ = self._interceptor.post_get_queue_with_metadata( 

1882 resp, response_metadata 

1883 ) 

1884 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1885 logging.DEBUG 

1886 ): # pragma: NO COVER 

1887 try: 

1888 response_payload = queue.Queue.to_json(response) 

1889 except: 

1890 response_payload = None 

1891 http_response = { 

1892 "payload": response_payload, 

1893 "headers": dict(response.headers), 

1894 "status": response.status_code, 

1895 } 

1896 _LOGGER.debug( 

1897 "Received response for google.cloud.tasks_v2.CloudTasksClient.get_queue", 

1898 extra={ 

1899 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1900 "rpcName": "GetQueue", 

1901 "metadata": http_response["headers"], 

1902 "httpResponse": http_response, 

1903 }, 

1904 ) 

1905 return resp 

1906 

1907 class _GetTask(_BaseCloudTasksRestTransport._BaseGetTask, CloudTasksRestStub): 

1908 def __hash__(self): 

1909 return hash("CloudTasksRestTransport.GetTask") 

1910 

1911 @staticmethod 

1912 def _get_response( 

1913 host, 

1914 metadata, 

1915 query_params, 

1916 session, 

1917 timeout, 

1918 transcoded_request, 

1919 body=None, 

1920 ): 

1921 uri = transcoded_request["uri"] 

1922 method = transcoded_request["method"] 

1923 headers = dict(metadata) 

1924 headers["Content-Type"] = "application/json" 

1925 response = getattr(session, method)( 

1926 "{host}{uri}".format(host=host, uri=uri), 

1927 timeout=timeout, 

1928 headers=headers, 

1929 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1930 ) 

1931 return response 

1932 

1933 def __call__( 

1934 self, 

1935 request: cloudtasks.GetTaskRequest, 

1936 *, 

1937 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1938 timeout: Optional[float] = None, 

1939 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1940 ) -> task.Task: 

1941 r"""Call the get task method over HTTP. 

1942 

1943 Args: 

1944 request (~.cloudtasks.GetTaskRequest): 

1945 The request object. Request message for getting a task using 

1946 [GetTask][google.cloud.tasks.v2.CloudTasks.GetTask]. 

1947 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1948 should be retried. 

1949 timeout (float): The timeout for this request. 

1950 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1951 sent along with the request as metadata. Normally, each value must be of type `str`, 

1952 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1953 be of type `bytes`. 

1954 

1955 Returns: 

1956 ~.task.Task: 

1957 A unit of scheduled work. 

1958 """ 

1959 

1960 http_options = _BaseCloudTasksRestTransport._BaseGetTask._get_http_options() 

1961 

1962 request, metadata = self._interceptor.pre_get_task(request, metadata) 

1963 transcoded_request = ( 

1964 _BaseCloudTasksRestTransport._BaseGetTask._get_transcoded_request( 

1965 http_options, request 

1966 ) 

1967 ) 

1968 

1969 # Jsonify the query params 

1970 query_params = ( 

1971 _BaseCloudTasksRestTransport._BaseGetTask._get_query_params_json( 

1972 transcoded_request 

1973 ) 

1974 ) 

1975 

1976 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1977 logging.DEBUG 

1978 ): # pragma: NO COVER 

1979 request_url = "{host}{uri}".format( 

1980 host=self._host, uri=transcoded_request["uri"] 

1981 ) 

1982 method = transcoded_request["method"] 

1983 try: 

1984 request_payload = type(request).to_json(request) 

1985 except: 

1986 request_payload = None 

1987 http_request = { 

1988 "payload": request_payload, 

1989 "requestMethod": method, 

1990 "requestUrl": request_url, 

1991 "headers": dict(metadata), 

1992 } 

1993 _LOGGER.debug( 

1994 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.GetTask", 

1995 extra={ 

1996 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

1997 "rpcName": "GetTask", 

1998 "httpRequest": http_request, 

1999 "metadata": http_request["headers"], 

2000 }, 

2001 ) 

2002 

2003 # Send the request 

2004 response = CloudTasksRestTransport._GetTask._get_response( 

2005 self._host, 

2006 metadata, 

2007 query_params, 

2008 self._session, 

2009 timeout, 

2010 transcoded_request, 

2011 ) 

2012 

2013 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2014 # subclass. 

2015 if response.status_code >= 400: 

2016 raise core_exceptions.from_http_response(response) 

2017 

2018 # Return the response 

2019 resp = task.Task() 

2020 pb_resp = task.Task.pb(resp) 

2021 

2022 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2023 

2024 resp = self._interceptor.post_get_task(resp) 

2025 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2026 resp, _ = self._interceptor.post_get_task_with_metadata( 

2027 resp, response_metadata 

2028 ) 

2029 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2030 logging.DEBUG 

2031 ): # pragma: NO COVER 

2032 try: 

2033 response_payload = task.Task.to_json(response) 

2034 except: 

2035 response_payload = None 

2036 http_response = { 

2037 "payload": response_payload, 

2038 "headers": dict(response.headers), 

2039 "status": response.status_code, 

2040 } 

2041 _LOGGER.debug( 

2042 "Received response for google.cloud.tasks_v2.CloudTasksClient.get_task", 

2043 extra={ 

2044 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2045 "rpcName": "GetTask", 

2046 "metadata": http_response["headers"], 

2047 "httpResponse": http_response, 

2048 }, 

2049 ) 

2050 return resp 

2051 

2052 class _ListQueues(_BaseCloudTasksRestTransport._BaseListQueues, CloudTasksRestStub): 

2053 def __hash__(self): 

2054 return hash("CloudTasksRestTransport.ListQueues") 

2055 

2056 @staticmethod 

2057 def _get_response( 

2058 host, 

2059 metadata, 

2060 query_params, 

2061 session, 

2062 timeout, 

2063 transcoded_request, 

2064 body=None, 

2065 ): 

2066 uri = transcoded_request["uri"] 

2067 method = transcoded_request["method"] 

2068 headers = dict(metadata) 

2069 headers["Content-Type"] = "application/json" 

2070 response = getattr(session, method)( 

2071 "{host}{uri}".format(host=host, uri=uri), 

2072 timeout=timeout, 

2073 headers=headers, 

2074 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2075 ) 

2076 return response 

2077 

2078 def __call__( 

2079 self, 

2080 request: cloudtasks.ListQueuesRequest, 

2081 *, 

2082 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2083 timeout: Optional[float] = None, 

2084 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2085 ) -> cloudtasks.ListQueuesResponse: 

2086 r"""Call the list queues method over HTTP. 

2087 

2088 Args: 

2089 request (~.cloudtasks.ListQueuesRequest): 

2090 The request object. Request message for 

2091 [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. 

2092 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2093 should be retried. 

2094 timeout (float): The timeout for this request. 

2095 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2096 sent along with the request as metadata. Normally, each value must be of type `str`, 

2097 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2098 be of type `bytes`. 

2099 

2100 Returns: 

2101 ~.cloudtasks.ListQueuesResponse: 

2102 Response message for 

2103 [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. 

2104 

2105 """ 

2106 

2107 http_options = ( 

2108 _BaseCloudTasksRestTransport._BaseListQueues._get_http_options() 

2109 ) 

2110 

2111 request, metadata = self._interceptor.pre_list_queues(request, metadata) 

2112 transcoded_request = ( 

2113 _BaseCloudTasksRestTransport._BaseListQueues._get_transcoded_request( 

2114 http_options, request 

2115 ) 

2116 ) 

2117 

2118 # Jsonify the query params 

2119 query_params = ( 

2120 _BaseCloudTasksRestTransport._BaseListQueues._get_query_params_json( 

2121 transcoded_request 

2122 ) 

2123 ) 

2124 

2125 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2126 logging.DEBUG 

2127 ): # pragma: NO COVER 

2128 request_url = "{host}{uri}".format( 

2129 host=self._host, uri=transcoded_request["uri"] 

2130 ) 

2131 method = transcoded_request["method"] 

2132 try: 

2133 request_payload = type(request).to_json(request) 

2134 except: 

2135 request_payload = None 

2136 http_request = { 

2137 "payload": request_payload, 

2138 "requestMethod": method, 

2139 "requestUrl": request_url, 

2140 "headers": dict(metadata), 

2141 } 

2142 _LOGGER.debug( 

2143 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.ListQueues", 

2144 extra={ 

2145 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2146 "rpcName": "ListQueues", 

2147 "httpRequest": http_request, 

2148 "metadata": http_request["headers"], 

2149 }, 

2150 ) 

2151 

2152 # Send the request 

2153 response = CloudTasksRestTransport._ListQueues._get_response( 

2154 self._host, 

2155 metadata, 

2156 query_params, 

2157 self._session, 

2158 timeout, 

2159 transcoded_request, 

2160 ) 

2161 

2162 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2163 # subclass. 

2164 if response.status_code >= 400: 

2165 raise core_exceptions.from_http_response(response) 

2166 

2167 # Return the response 

2168 resp = cloudtasks.ListQueuesResponse() 

2169 pb_resp = cloudtasks.ListQueuesResponse.pb(resp) 

2170 

2171 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2172 

2173 resp = self._interceptor.post_list_queues(resp) 

2174 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2175 resp, _ = self._interceptor.post_list_queues_with_metadata( 

2176 resp, response_metadata 

2177 ) 

2178 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2179 logging.DEBUG 

2180 ): # pragma: NO COVER 

2181 try: 

2182 response_payload = cloudtasks.ListQueuesResponse.to_json(response) 

2183 except: 

2184 response_payload = None 

2185 http_response = { 

2186 "payload": response_payload, 

2187 "headers": dict(response.headers), 

2188 "status": response.status_code, 

2189 } 

2190 _LOGGER.debug( 

2191 "Received response for google.cloud.tasks_v2.CloudTasksClient.list_queues", 

2192 extra={ 

2193 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2194 "rpcName": "ListQueues", 

2195 "metadata": http_response["headers"], 

2196 "httpResponse": http_response, 

2197 }, 

2198 ) 

2199 return resp 

2200 

2201 class _ListTasks(_BaseCloudTasksRestTransport._BaseListTasks, CloudTasksRestStub): 

2202 def __hash__(self): 

2203 return hash("CloudTasksRestTransport.ListTasks") 

2204 

2205 @staticmethod 

2206 def _get_response( 

2207 host, 

2208 metadata, 

2209 query_params, 

2210 session, 

2211 timeout, 

2212 transcoded_request, 

2213 body=None, 

2214 ): 

2215 uri = transcoded_request["uri"] 

2216 method = transcoded_request["method"] 

2217 headers = dict(metadata) 

2218 headers["Content-Type"] = "application/json" 

2219 response = getattr(session, method)( 

2220 "{host}{uri}".format(host=host, uri=uri), 

2221 timeout=timeout, 

2222 headers=headers, 

2223 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2224 ) 

2225 return response 

2226 

2227 def __call__( 

2228 self, 

2229 request: cloudtasks.ListTasksRequest, 

2230 *, 

2231 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2232 timeout: Optional[float] = None, 

2233 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2234 ) -> cloudtasks.ListTasksResponse: 

2235 r"""Call the list tasks method over HTTP. 

2236 

2237 Args: 

2238 request (~.cloudtasks.ListTasksRequest): 

2239 The request object. Request message for listing tasks using 

2240 [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. 

2241 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2242 should be retried. 

2243 timeout (float): The timeout for this request. 

2244 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2245 sent along with the request as metadata. Normally, each value must be of type `str`, 

2246 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2247 be of type `bytes`. 

2248 

2249 Returns: 

2250 ~.cloudtasks.ListTasksResponse: 

2251 Response message for listing tasks using 

2252 [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. 

2253 

2254 """ 

2255 

2256 http_options = ( 

2257 _BaseCloudTasksRestTransport._BaseListTasks._get_http_options() 

2258 ) 

2259 

2260 request, metadata = self._interceptor.pre_list_tasks(request, metadata) 

2261 transcoded_request = ( 

2262 _BaseCloudTasksRestTransport._BaseListTasks._get_transcoded_request( 

2263 http_options, request 

2264 ) 

2265 ) 

2266 

2267 # Jsonify the query params 

2268 query_params = ( 

2269 _BaseCloudTasksRestTransport._BaseListTasks._get_query_params_json( 

2270 transcoded_request 

2271 ) 

2272 ) 

2273 

2274 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2275 logging.DEBUG 

2276 ): # pragma: NO COVER 

2277 request_url = "{host}{uri}".format( 

2278 host=self._host, uri=transcoded_request["uri"] 

2279 ) 

2280 method = transcoded_request["method"] 

2281 try: 

2282 request_payload = type(request).to_json(request) 

2283 except: 

2284 request_payload = None 

2285 http_request = { 

2286 "payload": request_payload, 

2287 "requestMethod": method, 

2288 "requestUrl": request_url, 

2289 "headers": dict(metadata), 

2290 } 

2291 _LOGGER.debug( 

2292 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.ListTasks", 

2293 extra={ 

2294 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2295 "rpcName": "ListTasks", 

2296 "httpRequest": http_request, 

2297 "metadata": http_request["headers"], 

2298 }, 

2299 ) 

2300 

2301 # Send the request 

2302 response = CloudTasksRestTransport._ListTasks._get_response( 

2303 self._host, 

2304 metadata, 

2305 query_params, 

2306 self._session, 

2307 timeout, 

2308 transcoded_request, 

2309 ) 

2310 

2311 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2312 # subclass. 

2313 if response.status_code >= 400: 

2314 raise core_exceptions.from_http_response(response) 

2315 

2316 # Return the response 

2317 resp = cloudtasks.ListTasksResponse() 

2318 pb_resp = cloudtasks.ListTasksResponse.pb(resp) 

2319 

2320 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2321 

2322 resp = self._interceptor.post_list_tasks(resp) 

2323 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2324 resp, _ = self._interceptor.post_list_tasks_with_metadata( 

2325 resp, response_metadata 

2326 ) 

2327 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2328 logging.DEBUG 

2329 ): # pragma: NO COVER 

2330 try: 

2331 response_payload = cloudtasks.ListTasksResponse.to_json(response) 

2332 except: 

2333 response_payload = None 

2334 http_response = { 

2335 "payload": response_payload, 

2336 "headers": dict(response.headers), 

2337 "status": response.status_code, 

2338 } 

2339 _LOGGER.debug( 

2340 "Received response for google.cloud.tasks_v2.CloudTasksClient.list_tasks", 

2341 extra={ 

2342 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2343 "rpcName": "ListTasks", 

2344 "metadata": http_response["headers"], 

2345 "httpResponse": http_response, 

2346 }, 

2347 ) 

2348 return resp 

2349 

2350 class _PauseQueue(_BaseCloudTasksRestTransport._BasePauseQueue, CloudTasksRestStub): 

2351 def __hash__(self): 

2352 return hash("CloudTasksRestTransport.PauseQueue") 

2353 

2354 @staticmethod 

2355 def _get_response( 

2356 host, 

2357 metadata, 

2358 query_params, 

2359 session, 

2360 timeout, 

2361 transcoded_request, 

2362 body=None, 

2363 ): 

2364 uri = transcoded_request["uri"] 

2365 method = transcoded_request["method"] 

2366 headers = dict(metadata) 

2367 headers["Content-Type"] = "application/json" 

2368 response = getattr(session, method)( 

2369 "{host}{uri}".format(host=host, uri=uri), 

2370 timeout=timeout, 

2371 headers=headers, 

2372 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2373 data=body, 

2374 ) 

2375 return response 

2376 

2377 def __call__( 

2378 self, 

2379 request: cloudtasks.PauseQueueRequest, 

2380 *, 

2381 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2382 timeout: Optional[float] = None, 

2383 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2384 ) -> queue.Queue: 

2385 r"""Call the pause queue method over HTTP. 

2386 

2387 Args: 

2388 request (~.cloudtasks.PauseQueueRequest): 

2389 The request object. Request message for 

2390 [PauseQueue][google.cloud.tasks.v2.CloudTasks.PauseQueue]. 

2391 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2392 should be retried. 

2393 timeout (float): The timeout for this request. 

2394 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2395 sent along with the request as metadata. Normally, each value must be of type `str`, 

2396 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2397 be of type `bytes`. 

2398 

2399 Returns: 

2400 ~.queue.Queue: 

2401 A queue is a container of related 

2402 tasks. Queues are configured to manage 

2403 how those tasks are dispatched. 

2404 Configurable properties include rate 

2405 limits, retry options, queue types, and 

2406 others. 

2407 

2408 """ 

2409 

2410 http_options = ( 

2411 _BaseCloudTasksRestTransport._BasePauseQueue._get_http_options() 

2412 ) 

2413 

2414 request, metadata = self._interceptor.pre_pause_queue(request, metadata) 

2415 transcoded_request = ( 

2416 _BaseCloudTasksRestTransport._BasePauseQueue._get_transcoded_request( 

2417 http_options, request 

2418 ) 

2419 ) 

2420 

2421 body = _BaseCloudTasksRestTransport._BasePauseQueue._get_request_body_json( 

2422 transcoded_request 

2423 ) 

2424 

2425 # Jsonify the query params 

2426 query_params = ( 

2427 _BaseCloudTasksRestTransport._BasePauseQueue._get_query_params_json( 

2428 transcoded_request 

2429 ) 

2430 ) 

2431 

2432 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2433 logging.DEBUG 

2434 ): # pragma: NO COVER 

2435 request_url = "{host}{uri}".format( 

2436 host=self._host, uri=transcoded_request["uri"] 

2437 ) 

2438 method = transcoded_request["method"] 

2439 try: 

2440 request_payload = type(request).to_json(request) 

2441 except: 

2442 request_payload = None 

2443 http_request = { 

2444 "payload": request_payload, 

2445 "requestMethod": method, 

2446 "requestUrl": request_url, 

2447 "headers": dict(metadata), 

2448 } 

2449 _LOGGER.debug( 

2450 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.PauseQueue", 

2451 extra={ 

2452 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2453 "rpcName": "PauseQueue", 

2454 "httpRequest": http_request, 

2455 "metadata": http_request["headers"], 

2456 }, 

2457 ) 

2458 

2459 # Send the request 

2460 response = CloudTasksRestTransport._PauseQueue._get_response( 

2461 self._host, 

2462 metadata, 

2463 query_params, 

2464 self._session, 

2465 timeout, 

2466 transcoded_request, 

2467 body, 

2468 ) 

2469 

2470 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2471 # subclass. 

2472 if response.status_code >= 400: 

2473 raise core_exceptions.from_http_response(response) 

2474 

2475 # Return the response 

2476 resp = queue.Queue() 

2477 pb_resp = queue.Queue.pb(resp) 

2478 

2479 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2480 

2481 resp = self._interceptor.post_pause_queue(resp) 

2482 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2483 resp, _ = self._interceptor.post_pause_queue_with_metadata( 

2484 resp, response_metadata 

2485 ) 

2486 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2487 logging.DEBUG 

2488 ): # pragma: NO COVER 

2489 try: 

2490 response_payload = queue.Queue.to_json(response) 

2491 except: 

2492 response_payload = None 

2493 http_response = { 

2494 "payload": response_payload, 

2495 "headers": dict(response.headers), 

2496 "status": response.status_code, 

2497 } 

2498 _LOGGER.debug( 

2499 "Received response for google.cloud.tasks_v2.CloudTasksClient.pause_queue", 

2500 extra={ 

2501 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2502 "rpcName": "PauseQueue", 

2503 "metadata": http_response["headers"], 

2504 "httpResponse": http_response, 

2505 }, 

2506 ) 

2507 return resp 

2508 

2509 class _PurgeQueue(_BaseCloudTasksRestTransport._BasePurgeQueue, CloudTasksRestStub): 

2510 def __hash__(self): 

2511 return hash("CloudTasksRestTransport.PurgeQueue") 

2512 

2513 @staticmethod 

2514 def _get_response( 

2515 host, 

2516 metadata, 

2517 query_params, 

2518 session, 

2519 timeout, 

2520 transcoded_request, 

2521 body=None, 

2522 ): 

2523 uri = transcoded_request["uri"] 

2524 method = transcoded_request["method"] 

2525 headers = dict(metadata) 

2526 headers["Content-Type"] = "application/json" 

2527 response = getattr(session, method)( 

2528 "{host}{uri}".format(host=host, uri=uri), 

2529 timeout=timeout, 

2530 headers=headers, 

2531 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2532 data=body, 

2533 ) 

2534 return response 

2535 

2536 def __call__( 

2537 self, 

2538 request: cloudtasks.PurgeQueueRequest, 

2539 *, 

2540 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2541 timeout: Optional[float] = None, 

2542 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2543 ) -> queue.Queue: 

2544 r"""Call the purge queue method over HTTP. 

2545 

2546 Args: 

2547 request (~.cloudtasks.PurgeQueueRequest): 

2548 The request object. Request message for 

2549 [PurgeQueue][google.cloud.tasks.v2.CloudTasks.PurgeQueue]. 

2550 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2551 should be retried. 

2552 timeout (float): The timeout for this request. 

2553 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2554 sent along with the request as metadata. Normally, each value must be of type `str`, 

2555 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2556 be of type `bytes`. 

2557 

2558 Returns: 

2559 ~.queue.Queue: 

2560 A queue is a container of related 

2561 tasks. Queues are configured to manage 

2562 how those tasks are dispatched. 

2563 Configurable properties include rate 

2564 limits, retry options, queue types, and 

2565 others. 

2566 

2567 """ 

2568 

2569 http_options = ( 

2570 _BaseCloudTasksRestTransport._BasePurgeQueue._get_http_options() 

2571 ) 

2572 

2573 request, metadata = self._interceptor.pre_purge_queue(request, metadata) 

2574 transcoded_request = ( 

2575 _BaseCloudTasksRestTransport._BasePurgeQueue._get_transcoded_request( 

2576 http_options, request 

2577 ) 

2578 ) 

2579 

2580 body = _BaseCloudTasksRestTransport._BasePurgeQueue._get_request_body_json( 

2581 transcoded_request 

2582 ) 

2583 

2584 # Jsonify the query params 

2585 query_params = ( 

2586 _BaseCloudTasksRestTransport._BasePurgeQueue._get_query_params_json( 

2587 transcoded_request 

2588 ) 

2589 ) 

2590 

2591 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2592 logging.DEBUG 

2593 ): # pragma: NO COVER 

2594 request_url = "{host}{uri}".format( 

2595 host=self._host, uri=transcoded_request["uri"] 

2596 ) 

2597 method = transcoded_request["method"] 

2598 try: 

2599 request_payload = type(request).to_json(request) 

2600 except: 

2601 request_payload = None 

2602 http_request = { 

2603 "payload": request_payload, 

2604 "requestMethod": method, 

2605 "requestUrl": request_url, 

2606 "headers": dict(metadata), 

2607 } 

2608 _LOGGER.debug( 

2609 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.PurgeQueue", 

2610 extra={ 

2611 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2612 "rpcName": "PurgeQueue", 

2613 "httpRequest": http_request, 

2614 "metadata": http_request["headers"], 

2615 }, 

2616 ) 

2617 

2618 # Send the request 

2619 response = CloudTasksRestTransport._PurgeQueue._get_response( 

2620 self._host, 

2621 metadata, 

2622 query_params, 

2623 self._session, 

2624 timeout, 

2625 transcoded_request, 

2626 body, 

2627 ) 

2628 

2629 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2630 # subclass. 

2631 if response.status_code >= 400: 

2632 raise core_exceptions.from_http_response(response) 

2633 

2634 # Return the response 

2635 resp = queue.Queue() 

2636 pb_resp = queue.Queue.pb(resp) 

2637 

2638 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2639 

2640 resp = self._interceptor.post_purge_queue(resp) 

2641 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2642 resp, _ = self._interceptor.post_purge_queue_with_metadata( 

2643 resp, response_metadata 

2644 ) 

2645 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2646 logging.DEBUG 

2647 ): # pragma: NO COVER 

2648 try: 

2649 response_payload = queue.Queue.to_json(response) 

2650 except: 

2651 response_payload = None 

2652 http_response = { 

2653 "payload": response_payload, 

2654 "headers": dict(response.headers), 

2655 "status": response.status_code, 

2656 } 

2657 _LOGGER.debug( 

2658 "Received response for google.cloud.tasks_v2.CloudTasksClient.purge_queue", 

2659 extra={ 

2660 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2661 "rpcName": "PurgeQueue", 

2662 "metadata": http_response["headers"], 

2663 "httpResponse": http_response, 

2664 }, 

2665 ) 

2666 return resp 

2667 

2668 class _ResumeQueue( 

2669 _BaseCloudTasksRestTransport._BaseResumeQueue, CloudTasksRestStub 

2670 ): 

2671 def __hash__(self): 

2672 return hash("CloudTasksRestTransport.ResumeQueue") 

2673 

2674 @staticmethod 

2675 def _get_response( 

2676 host, 

2677 metadata, 

2678 query_params, 

2679 session, 

2680 timeout, 

2681 transcoded_request, 

2682 body=None, 

2683 ): 

2684 uri = transcoded_request["uri"] 

2685 method = transcoded_request["method"] 

2686 headers = dict(metadata) 

2687 headers["Content-Type"] = "application/json" 

2688 response = getattr(session, method)( 

2689 "{host}{uri}".format(host=host, uri=uri), 

2690 timeout=timeout, 

2691 headers=headers, 

2692 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2693 data=body, 

2694 ) 

2695 return response 

2696 

2697 def __call__( 

2698 self, 

2699 request: cloudtasks.ResumeQueueRequest, 

2700 *, 

2701 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2702 timeout: Optional[float] = None, 

2703 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2704 ) -> queue.Queue: 

2705 r"""Call the resume queue method over HTTP. 

2706 

2707 Args: 

2708 request (~.cloudtasks.ResumeQueueRequest): 

2709 The request object. Request message for 

2710 [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. 

2711 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2712 should be retried. 

2713 timeout (float): The timeout for this request. 

2714 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2715 sent along with the request as metadata. Normally, each value must be of type `str`, 

2716 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2717 be of type `bytes`. 

2718 

2719 Returns: 

2720 ~.queue.Queue: 

2721 A queue is a container of related 

2722 tasks. Queues are configured to manage 

2723 how those tasks are dispatched. 

2724 Configurable properties include rate 

2725 limits, retry options, queue types, and 

2726 others. 

2727 

2728 """ 

2729 

2730 http_options = ( 

2731 _BaseCloudTasksRestTransport._BaseResumeQueue._get_http_options() 

2732 ) 

2733 

2734 request, metadata = self._interceptor.pre_resume_queue(request, metadata) 

2735 transcoded_request = ( 

2736 _BaseCloudTasksRestTransport._BaseResumeQueue._get_transcoded_request( 

2737 http_options, request 

2738 ) 

2739 ) 

2740 

2741 body = _BaseCloudTasksRestTransport._BaseResumeQueue._get_request_body_json( 

2742 transcoded_request 

2743 ) 

2744 

2745 # Jsonify the query params 

2746 query_params = ( 

2747 _BaseCloudTasksRestTransport._BaseResumeQueue._get_query_params_json( 

2748 transcoded_request 

2749 ) 

2750 ) 

2751 

2752 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2753 logging.DEBUG 

2754 ): # pragma: NO COVER 

2755 request_url = "{host}{uri}".format( 

2756 host=self._host, uri=transcoded_request["uri"] 

2757 ) 

2758 method = transcoded_request["method"] 

2759 try: 

2760 request_payload = type(request).to_json(request) 

2761 except: 

2762 request_payload = None 

2763 http_request = { 

2764 "payload": request_payload, 

2765 "requestMethod": method, 

2766 "requestUrl": request_url, 

2767 "headers": dict(metadata), 

2768 } 

2769 _LOGGER.debug( 

2770 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.ResumeQueue", 

2771 extra={ 

2772 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2773 "rpcName": "ResumeQueue", 

2774 "httpRequest": http_request, 

2775 "metadata": http_request["headers"], 

2776 }, 

2777 ) 

2778 

2779 # Send the request 

2780 response = CloudTasksRestTransport._ResumeQueue._get_response( 

2781 self._host, 

2782 metadata, 

2783 query_params, 

2784 self._session, 

2785 timeout, 

2786 transcoded_request, 

2787 body, 

2788 ) 

2789 

2790 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2791 # subclass. 

2792 if response.status_code >= 400: 

2793 raise core_exceptions.from_http_response(response) 

2794 

2795 # Return the response 

2796 resp = queue.Queue() 

2797 pb_resp = queue.Queue.pb(resp) 

2798 

2799 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2800 

2801 resp = self._interceptor.post_resume_queue(resp) 

2802 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2803 resp, _ = self._interceptor.post_resume_queue_with_metadata( 

2804 resp, response_metadata 

2805 ) 

2806 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2807 logging.DEBUG 

2808 ): # pragma: NO COVER 

2809 try: 

2810 response_payload = queue.Queue.to_json(response) 

2811 except: 

2812 response_payload = None 

2813 http_response = { 

2814 "payload": response_payload, 

2815 "headers": dict(response.headers), 

2816 "status": response.status_code, 

2817 } 

2818 _LOGGER.debug( 

2819 "Received response for google.cloud.tasks_v2.CloudTasksClient.resume_queue", 

2820 extra={ 

2821 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2822 "rpcName": "ResumeQueue", 

2823 "metadata": http_response["headers"], 

2824 "httpResponse": http_response, 

2825 }, 

2826 ) 

2827 return resp 

2828 

2829 class _RunTask(_BaseCloudTasksRestTransport._BaseRunTask, CloudTasksRestStub): 

2830 def __hash__(self): 

2831 return hash("CloudTasksRestTransport.RunTask") 

2832 

2833 @staticmethod 

2834 def _get_response( 

2835 host, 

2836 metadata, 

2837 query_params, 

2838 session, 

2839 timeout, 

2840 transcoded_request, 

2841 body=None, 

2842 ): 

2843 uri = transcoded_request["uri"] 

2844 method = transcoded_request["method"] 

2845 headers = dict(metadata) 

2846 headers["Content-Type"] = "application/json" 

2847 response = getattr(session, method)( 

2848 "{host}{uri}".format(host=host, uri=uri), 

2849 timeout=timeout, 

2850 headers=headers, 

2851 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2852 data=body, 

2853 ) 

2854 return response 

2855 

2856 def __call__( 

2857 self, 

2858 request: cloudtasks.RunTaskRequest, 

2859 *, 

2860 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2861 timeout: Optional[float] = None, 

2862 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2863 ) -> task.Task: 

2864 r"""Call the run task method over HTTP. 

2865 

2866 Args: 

2867 request (~.cloudtasks.RunTaskRequest): 

2868 The request object. Request message for forcing a task to run now using 

2869 [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask]. 

2870 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2871 should be retried. 

2872 timeout (float): The timeout for this request. 

2873 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2874 sent along with the request as metadata. Normally, each value must be of type `str`, 

2875 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2876 be of type `bytes`. 

2877 

2878 Returns: 

2879 ~.task.Task: 

2880 A unit of scheduled work. 

2881 """ 

2882 

2883 http_options = _BaseCloudTasksRestTransport._BaseRunTask._get_http_options() 

2884 

2885 request, metadata = self._interceptor.pre_run_task(request, metadata) 

2886 transcoded_request = ( 

2887 _BaseCloudTasksRestTransport._BaseRunTask._get_transcoded_request( 

2888 http_options, request 

2889 ) 

2890 ) 

2891 

2892 body = _BaseCloudTasksRestTransport._BaseRunTask._get_request_body_json( 

2893 transcoded_request 

2894 ) 

2895 

2896 # Jsonify the query params 

2897 query_params = ( 

2898 _BaseCloudTasksRestTransport._BaseRunTask._get_query_params_json( 

2899 transcoded_request 

2900 ) 

2901 ) 

2902 

2903 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2904 logging.DEBUG 

2905 ): # pragma: NO COVER 

2906 request_url = "{host}{uri}".format( 

2907 host=self._host, uri=transcoded_request["uri"] 

2908 ) 

2909 method = transcoded_request["method"] 

2910 try: 

2911 request_payload = type(request).to_json(request) 

2912 except: 

2913 request_payload = None 

2914 http_request = { 

2915 "payload": request_payload, 

2916 "requestMethod": method, 

2917 "requestUrl": request_url, 

2918 "headers": dict(metadata), 

2919 } 

2920 _LOGGER.debug( 

2921 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.RunTask", 

2922 extra={ 

2923 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2924 "rpcName": "RunTask", 

2925 "httpRequest": http_request, 

2926 "metadata": http_request["headers"], 

2927 }, 

2928 ) 

2929 

2930 # Send the request 

2931 response = CloudTasksRestTransport._RunTask._get_response( 

2932 self._host, 

2933 metadata, 

2934 query_params, 

2935 self._session, 

2936 timeout, 

2937 transcoded_request, 

2938 body, 

2939 ) 

2940 

2941 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2942 # subclass. 

2943 if response.status_code >= 400: 

2944 raise core_exceptions.from_http_response(response) 

2945 

2946 # Return the response 

2947 resp = task.Task() 

2948 pb_resp = task.Task.pb(resp) 

2949 

2950 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2951 

2952 resp = self._interceptor.post_run_task(resp) 

2953 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2954 resp, _ = self._interceptor.post_run_task_with_metadata( 

2955 resp, response_metadata 

2956 ) 

2957 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2958 logging.DEBUG 

2959 ): # pragma: NO COVER 

2960 try: 

2961 response_payload = task.Task.to_json(response) 

2962 except: 

2963 response_payload = None 

2964 http_response = { 

2965 "payload": response_payload, 

2966 "headers": dict(response.headers), 

2967 "status": response.status_code, 

2968 } 

2969 _LOGGER.debug( 

2970 "Received response for google.cloud.tasks_v2.CloudTasksClient.run_task", 

2971 extra={ 

2972 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

2973 "rpcName": "RunTask", 

2974 "metadata": http_response["headers"], 

2975 "httpResponse": http_response, 

2976 }, 

2977 ) 

2978 return resp 

2979 

2980 class _SetIamPolicy( 

2981 _BaseCloudTasksRestTransport._BaseSetIamPolicy, CloudTasksRestStub 

2982 ): 

2983 def __hash__(self): 

2984 return hash("CloudTasksRestTransport.SetIamPolicy") 

2985 

2986 @staticmethod 

2987 def _get_response( 

2988 host, 

2989 metadata, 

2990 query_params, 

2991 session, 

2992 timeout, 

2993 transcoded_request, 

2994 body=None, 

2995 ): 

2996 uri = transcoded_request["uri"] 

2997 method = transcoded_request["method"] 

2998 headers = dict(metadata) 

2999 headers["Content-Type"] = "application/json" 

3000 response = getattr(session, method)( 

3001 "{host}{uri}".format(host=host, uri=uri), 

3002 timeout=timeout, 

3003 headers=headers, 

3004 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3005 data=body, 

3006 ) 

3007 return response 

3008 

3009 def __call__( 

3010 self, 

3011 request: iam_policy_pb2.SetIamPolicyRequest, 

3012 *, 

3013 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3014 timeout: Optional[float] = None, 

3015 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3016 ) -> policy_pb2.Policy: 

3017 r"""Call the set iam policy method over HTTP. 

3018 

3019 Args: 

3020 request (~.iam_policy_pb2.SetIamPolicyRequest): 

3021 The request object. Request message for ``SetIamPolicy`` method. 

3022 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3023 should be retried. 

3024 timeout (float): The timeout for this request. 

3025 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3026 sent along with the request as metadata. Normally, each value must be of type `str`, 

3027 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3028 be of type `bytes`. 

3029 

3030 Returns: 

3031 ~.policy_pb2.Policy: 

3032 An Identity and Access Management (IAM) policy, which 

3033 specifies access controls for Google Cloud resources. 

3034 

3035 A ``Policy`` is a collection of ``bindings``. A 

3036 ``binding`` binds one or more ``members``, or 

3037 principals, to a single ``role``. Principals can be user 

3038 accounts, service accounts, Google groups, and domains 

3039 (such as G Suite). A ``role`` is a named list of 

3040 permissions; each ``role`` can be an IAM predefined role 

3041 or a user-created custom role. 

3042 

3043 For some types of Google Cloud resources, a ``binding`` 

3044 can also specify a ``condition``, which is a logical 

3045 expression that allows access to a resource only if the 

3046 expression evaluates to ``true``. A condition can add 

3047 constraints based on attributes of the request, the 

3048 resource, or both. To learn which resources support 

3049 conditions in their IAM policies, see the `IAM 

3050 documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. 

3051 

3052 **JSON example:** 

3053 

3054 :: 

3055 

3056 { 

3057 "bindings": [ 

3058 { 

3059 "role": "roles/resourcemanager.organizationAdmin", 

3060 "members": [ 

3061 "user:mike@example.com", 

3062 "group:admins@example.com", 

3063 "domain:google.com", 

3064 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

3065 ] 

3066 }, 

3067 { 

3068 "role": "roles/resourcemanager.organizationViewer", 

3069 "members": [ 

3070 "user:eve@example.com" 

3071 ], 

3072 "condition": { 

3073 "title": "expirable access", 

3074 "description": "Does not grant access after Sep 2020", 

3075 "expression": "request.time < 

3076 timestamp('2020-10-01T00:00:00.000Z')", 

3077 } 

3078 } 

3079 ], 

3080 "etag": "BwWWja0YfJA=", 

3081 "version": 3 

3082 } 

3083 

3084 **YAML example:** 

3085 

3086 :: 

3087 

3088 bindings: 

3089 - members: 

3090 - user:mike@example.com 

3091 - group:admins@example.com 

3092 - domain:google.com 

3093 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

3094 role: roles/resourcemanager.organizationAdmin 

3095 - members: 

3096 - user:eve@example.com 

3097 role: roles/resourcemanager.organizationViewer 

3098 condition: 

3099 title: expirable access 

3100 description: Does not grant access after Sep 2020 

3101 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

3102 etag: BwWWja0YfJA= 

3103 version: 3 

3104 

3105 For a description of IAM and its features, see the `IAM 

3106 documentation <https://cloud.google.com/iam/docs/>`__. 

3107 

3108 """ 

3109 

3110 http_options = ( 

3111 _BaseCloudTasksRestTransport._BaseSetIamPolicy._get_http_options() 

3112 ) 

3113 

3114 request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) 

3115 transcoded_request = ( 

3116 _BaseCloudTasksRestTransport._BaseSetIamPolicy._get_transcoded_request( 

3117 http_options, request 

3118 ) 

3119 ) 

3120 

3121 body = ( 

3122 _BaseCloudTasksRestTransport._BaseSetIamPolicy._get_request_body_json( 

3123 transcoded_request 

3124 ) 

3125 ) 

3126 

3127 # Jsonify the query params 

3128 query_params = ( 

3129 _BaseCloudTasksRestTransport._BaseSetIamPolicy._get_query_params_json( 

3130 transcoded_request 

3131 ) 

3132 ) 

3133 

3134 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3135 logging.DEBUG 

3136 ): # pragma: NO COVER 

3137 request_url = "{host}{uri}".format( 

3138 host=self._host, uri=transcoded_request["uri"] 

3139 ) 

3140 method = transcoded_request["method"] 

3141 try: 

3142 request_payload = json_format.MessageToJson(request) 

3143 except: 

3144 request_payload = None 

3145 http_request = { 

3146 "payload": request_payload, 

3147 "requestMethod": method, 

3148 "requestUrl": request_url, 

3149 "headers": dict(metadata), 

3150 } 

3151 _LOGGER.debug( 

3152 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.SetIamPolicy", 

3153 extra={ 

3154 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3155 "rpcName": "SetIamPolicy", 

3156 "httpRequest": http_request, 

3157 "metadata": http_request["headers"], 

3158 }, 

3159 ) 

3160 

3161 # Send the request 

3162 response = CloudTasksRestTransport._SetIamPolicy._get_response( 

3163 self._host, 

3164 metadata, 

3165 query_params, 

3166 self._session, 

3167 timeout, 

3168 transcoded_request, 

3169 body, 

3170 ) 

3171 

3172 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3173 # subclass. 

3174 if response.status_code >= 400: 

3175 raise core_exceptions.from_http_response(response) 

3176 

3177 # Return the response 

3178 resp = policy_pb2.Policy() 

3179 pb_resp = resp 

3180 

3181 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

3182 

3183 resp = self._interceptor.post_set_iam_policy(resp) 

3184 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

3185 resp, _ = self._interceptor.post_set_iam_policy_with_metadata( 

3186 resp, response_metadata 

3187 ) 

3188 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3189 logging.DEBUG 

3190 ): # pragma: NO COVER 

3191 try: 

3192 response_payload = json_format.MessageToJson(resp) 

3193 except: 

3194 response_payload = None 

3195 http_response = { 

3196 "payload": response_payload, 

3197 "headers": dict(response.headers), 

3198 "status": response.status_code, 

3199 } 

3200 _LOGGER.debug( 

3201 "Received response for google.cloud.tasks_v2.CloudTasksClient.set_iam_policy", 

3202 extra={ 

3203 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3204 "rpcName": "SetIamPolicy", 

3205 "metadata": http_response["headers"], 

3206 "httpResponse": http_response, 

3207 }, 

3208 ) 

3209 return resp 

3210 

3211 class _TestIamPermissions( 

3212 _BaseCloudTasksRestTransport._BaseTestIamPermissions, CloudTasksRestStub 

3213 ): 

3214 def __hash__(self): 

3215 return hash("CloudTasksRestTransport.TestIamPermissions") 

3216 

3217 @staticmethod 

3218 def _get_response( 

3219 host, 

3220 metadata, 

3221 query_params, 

3222 session, 

3223 timeout, 

3224 transcoded_request, 

3225 body=None, 

3226 ): 

3227 uri = transcoded_request["uri"] 

3228 method = transcoded_request["method"] 

3229 headers = dict(metadata) 

3230 headers["Content-Type"] = "application/json" 

3231 response = getattr(session, method)( 

3232 "{host}{uri}".format(host=host, uri=uri), 

3233 timeout=timeout, 

3234 headers=headers, 

3235 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3236 data=body, 

3237 ) 

3238 return response 

3239 

3240 def __call__( 

3241 self, 

3242 request: iam_policy_pb2.TestIamPermissionsRequest, 

3243 *, 

3244 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3245 timeout: Optional[float] = None, 

3246 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3247 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

3248 r"""Call the test iam permissions method over HTTP. 

3249 

3250 Args: 

3251 request (~.iam_policy_pb2.TestIamPermissionsRequest): 

3252 The request object. Request message for ``TestIamPermissions`` method. 

3253 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3254 should be retried. 

3255 timeout (float): The timeout for this request. 

3256 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3257 sent along with the request as metadata. Normally, each value must be of type `str`, 

3258 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3259 be of type `bytes`. 

3260 

3261 Returns: 

3262 ~.iam_policy_pb2.TestIamPermissionsResponse: 

3263 Response message for ``TestIamPermissions`` method. 

3264 """ 

3265 

3266 http_options = ( 

3267 _BaseCloudTasksRestTransport._BaseTestIamPermissions._get_http_options() 

3268 ) 

3269 

3270 request, metadata = self._interceptor.pre_test_iam_permissions( 

3271 request, metadata 

3272 ) 

3273 transcoded_request = _BaseCloudTasksRestTransport._BaseTestIamPermissions._get_transcoded_request( 

3274 http_options, request 

3275 ) 

3276 

3277 body = _BaseCloudTasksRestTransport._BaseTestIamPermissions._get_request_body_json( 

3278 transcoded_request 

3279 ) 

3280 

3281 # Jsonify the query params 

3282 query_params = _BaseCloudTasksRestTransport._BaseTestIamPermissions._get_query_params_json( 

3283 transcoded_request 

3284 ) 

3285 

3286 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3287 logging.DEBUG 

3288 ): # pragma: NO COVER 

3289 request_url = "{host}{uri}".format( 

3290 host=self._host, uri=transcoded_request["uri"] 

3291 ) 

3292 method = transcoded_request["method"] 

3293 try: 

3294 request_payload = json_format.MessageToJson(request) 

3295 except: 

3296 request_payload = None 

3297 http_request = { 

3298 "payload": request_payload, 

3299 "requestMethod": method, 

3300 "requestUrl": request_url, 

3301 "headers": dict(metadata), 

3302 } 

3303 _LOGGER.debug( 

3304 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.TestIamPermissions", 

3305 extra={ 

3306 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3307 "rpcName": "TestIamPermissions", 

3308 "httpRequest": http_request, 

3309 "metadata": http_request["headers"], 

3310 }, 

3311 ) 

3312 

3313 # Send the request 

3314 response = CloudTasksRestTransport._TestIamPermissions._get_response( 

3315 self._host, 

3316 metadata, 

3317 query_params, 

3318 self._session, 

3319 timeout, 

3320 transcoded_request, 

3321 body, 

3322 ) 

3323 

3324 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3325 # subclass. 

3326 if response.status_code >= 400: 

3327 raise core_exceptions.from_http_response(response) 

3328 

3329 # Return the response 

3330 resp = iam_policy_pb2.TestIamPermissionsResponse() 

3331 pb_resp = resp 

3332 

3333 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

3334 

3335 resp = self._interceptor.post_test_iam_permissions(resp) 

3336 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

3337 resp, _ = self._interceptor.post_test_iam_permissions_with_metadata( 

3338 resp, response_metadata 

3339 ) 

3340 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3341 logging.DEBUG 

3342 ): # pragma: NO COVER 

3343 try: 

3344 response_payload = json_format.MessageToJson(resp) 

3345 except: 

3346 response_payload = None 

3347 http_response = { 

3348 "payload": response_payload, 

3349 "headers": dict(response.headers), 

3350 "status": response.status_code, 

3351 } 

3352 _LOGGER.debug( 

3353 "Received response for google.cloud.tasks_v2.CloudTasksClient.test_iam_permissions", 

3354 extra={ 

3355 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3356 "rpcName": "TestIamPermissions", 

3357 "metadata": http_response["headers"], 

3358 "httpResponse": http_response, 

3359 }, 

3360 ) 

3361 return resp 

3362 

3363 class _UpdateQueue( 

3364 _BaseCloudTasksRestTransport._BaseUpdateQueue, CloudTasksRestStub 

3365 ): 

3366 def __hash__(self): 

3367 return hash("CloudTasksRestTransport.UpdateQueue") 

3368 

3369 @staticmethod 

3370 def _get_response( 

3371 host, 

3372 metadata, 

3373 query_params, 

3374 session, 

3375 timeout, 

3376 transcoded_request, 

3377 body=None, 

3378 ): 

3379 uri = transcoded_request["uri"] 

3380 method = transcoded_request["method"] 

3381 headers = dict(metadata) 

3382 headers["Content-Type"] = "application/json" 

3383 response = getattr(session, method)( 

3384 "{host}{uri}".format(host=host, uri=uri), 

3385 timeout=timeout, 

3386 headers=headers, 

3387 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3388 data=body, 

3389 ) 

3390 return response 

3391 

3392 def __call__( 

3393 self, 

3394 request: cloudtasks.UpdateQueueRequest, 

3395 *, 

3396 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3397 timeout: Optional[float] = None, 

3398 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3399 ) -> gct_queue.Queue: 

3400 r"""Call the update queue method over HTTP. 

3401 

3402 Args: 

3403 request (~.cloudtasks.UpdateQueueRequest): 

3404 The request object. Request message for 

3405 [UpdateQueue][google.cloud.tasks.v2.CloudTasks.UpdateQueue]. 

3406 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3407 should be retried. 

3408 timeout (float): The timeout for this request. 

3409 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3410 sent along with the request as metadata. Normally, each value must be of type `str`, 

3411 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3412 be of type `bytes`. 

3413 

3414 Returns: 

3415 ~.gct_queue.Queue: 

3416 A queue is a container of related 

3417 tasks. Queues are configured to manage 

3418 how those tasks are dispatched. 

3419 Configurable properties include rate 

3420 limits, retry options, queue types, and 

3421 others. 

3422 

3423 """ 

3424 

3425 http_options = ( 

3426 _BaseCloudTasksRestTransport._BaseUpdateQueue._get_http_options() 

3427 ) 

3428 

3429 request, metadata = self._interceptor.pre_update_queue(request, metadata) 

3430 transcoded_request = ( 

3431 _BaseCloudTasksRestTransport._BaseUpdateQueue._get_transcoded_request( 

3432 http_options, request 

3433 ) 

3434 ) 

3435 

3436 body = _BaseCloudTasksRestTransport._BaseUpdateQueue._get_request_body_json( 

3437 transcoded_request 

3438 ) 

3439 

3440 # Jsonify the query params 

3441 query_params = ( 

3442 _BaseCloudTasksRestTransport._BaseUpdateQueue._get_query_params_json( 

3443 transcoded_request 

3444 ) 

3445 ) 

3446 

3447 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3448 logging.DEBUG 

3449 ): # pragma: NO COVER 

3450 request_url = "{host}{uri}".format( 

3451 host=self._host, uri=transcoded_request["uri"] 

3452 ) 

3453 method = transcoded_request["method"] 

3454 try: 

3455 request_payload = type(request).to_json(request) 

3456 except: 

3457 request_payload = None 

3458 http_request = { 

3459 "payload": request_payload, 

3460 "requestMethod": method, 

3461 "requestUrl": request_url, 

3462 "headers": dict(metadata), 

3463 } 

3464 _LOGGER.debug( 

3465 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.UpdateQueue", 

3466 extra={ 

3467 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3468 "rpcName": "UpdateQueue", 

3469 "httpRequest": http_request, 

3470 "metadata": http_request["headers"], 

3471 }, 

3472 ) 

3473 

3474 # Send the request 

3475 response = CloudTasksRestTransport._UpdateQueue._get_response( 

3476 self._host, 

3477 metadata, 

3478 query_params, 

3479 self._session, 

3480 timeout, 

3481 transcoded_request, 

3482 body, 

3483 ) 

3484 

3485 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3486 # subclass. 

3487 if response.status_code >= 400: 

3488 raise core_exceptions.from_http_response(response) 

3489 

3490 # Return the response 

3491 resp = gct_queue.Queue() 

3492 pb_resp = gct_queue.Queue.pb(resp) 

3493 

3494 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

3495 

3496 resp = self._interceptor.post_update_queue(resp) 

3497 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

3498 resp, _ = self._interceptor.post_update_queue_with_metadata( 

3499 resp, response_metadata 

3500 ) 

3501 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3502 logging.DEBUG 

3503 ): # pragma: NO COVER 

3504 try: 

3505 response_payload = gct_queue.Queue.to_json(response) 

3506 except: 

3507 response_payload = None 

3508 http_response = { 

3509 "payload": response_payload, 

3510 "headers": dict(response.headers), 

3511 "status": response.status_code, 

3512 } 

3513 _LOGGER.debug( 

3514 "Received response for google.cloud.tasks_v2.CloudTasksClient.update_queue", 

3515 extra={ 

3516 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3517 "rpcName": "UpdateQueue", 

3518 "metadata": http_response["headers"], 

3519 "httpResponse": http_response, 

3520 }, 

3521 ) 

3522 return resp 

3523 

3524 @property 

3525 def create_queue( 

3526 self, 

3527 ) -> Callable[[cloudtasks.CreateQueueRequest], gct_queue.Queue]: 

3528 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3529 # In C++ this would require a dynamic_cast 

3530 return self._CreateQueue(self._session, self._host, self._interceptor) # type: ignore 

3531 

3532 @property 

3533 def create_task(self) -> Callable[[cloudtasks.CreateTaskRequest], gct_task.Task]: 

3534 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3535 # In C++ this would require a dynamic_cast 

3536 return self._CreateTask(self._session, self._host, self._interceptor) # type: ignore 

3537 

3538 @property 

3539 def delete_queue( 

3540 self, 

3541 ) -> Callable[[cloudtasks.DeleteQueueRequest], empty_pb2.Empty]: 

3542 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3543 # In C++ this would require a dynamic_cast 

3544 return self._DeleteQueue(self._session, self._host, self._interceptor) # type: ignore 

3545 

3546 @property 

3547 def delete_task(self) -> Callable[[cloudtasks.DeleteTaskRequest], empty_pb2.Empty]: 

3548 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3549 # In C++ this would require a dynamic_cast 

3550 return self._DeleteTask(self._session, self._host, self._interceptor) # type: ignore 

3551 

3552 @property 

3553 def get_iam_policy( 

3554 self, 

3555 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: 

3556 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3557 # In C++ this would require a dynamic_cast 

3558 return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore 

3559 

3560 @property 

3561 def get_queue(self) -> Callable[[cloudtasks.GetQueueRequest], queue.Queue]: 

3562 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3563 # In C++ this would require a dynamic_cast 

3564 return self._GetQueue(self._session, self._host, self._interceptor) # type: ignore 

3565 

3566 @property 

3567 def get_task(self) -> Callable[[cloudtasks.GetTaskRequest], task.Task]: 

3568 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3569 # In C++ this would require a dynamic_cast 

3570 return self._GetTask(self._session, self._host, self._interceptor) # type: ignore 

3571 

3572 @property 

3573 def list_queues( 

3574 self, 

3575 ) -> Callable[[cloudtasks.ListQueuesRequest], cloudtasks.ListQueuesResponse]: 

3576 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3577 # In C++ this would require a dynamic_cast 

3578 return self._ListQueues(self._session, self._host, self._interceptor) # type: ignore 

3579 

3580 @property 

3581 def list_tasks( 

3582 self, 

3583 ) -> Callable[[cloudtasks.ListTasksRequest], cloudtasks.ListTasksResponse]: 

3584 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3585 # In C++ this would require a dynamic_cast 

3586 return self._ListTasks(self._session, self._host, self._interceptor) # type: ignore 

3587 

3588 @property 

3589 def pause_queue(self) -> Callable[[cloudtasks.PauseQueueRequest], queue.Queue]: 

3590 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3591 # In C++ this would require a dynamic_cast 

3592 return self._PauseQueue(self._session, self._host, self._interceptor) # type: ignore 

3593 

3594 @property 

3595 def purge_queue(self) -> Callable[[cloudtasks.PurgeQueueRequest], queue.Queue]: 

3596 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3597 # In C++ this would require a dynamic_cast 

3598 return self._PurgeQueue(self._session, self._host, self._interceptor) # type: ignore 

3599 

3600 @property 

3601 def resume_queue(self) -> Callable[[cloudtasks.ResumeQueueRequest], queue.Queue]: 

3602 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3603 # In C++ this would require a dynamic_cast 

3604 return self._ResumeQueue(self._session, self._host, self._interceptor) # type: ignore 

3605 

3606 @property 

3607 def run_task(self) -> Callable[[cloudtasks.RunTaskRequest], task.Task]: 

3608 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3609 # In C++ this would require a dynamic_cast 

3610 return self._RunTask(self._session, self._host, self._interceptor) # type: ignore 

3611 

3612 @property 

3613 def set_iam_policy( 

3614 self, 

3615 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: 

3616 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3617 # In C++ this would require a dynamic_cast 

3618 return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore 

3619 

3620 @property 

3621 def test_iam_permissions( 

3622 self, 

3623 ) -> Callable[ 

3624 [iam_policy_pb2.TestIamPermissionsRequest], 

3625 iam_policy_pb2.TestIamPermissionsResponse, 

3626 ]: 

3627 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3628 # In C++ this would require a dynamic_cast 

3629 return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore 

3630 

3631 @property 

3632 def update_queue( 

3633 self, 

3634 ) -> Callable[[cloudtasks.UpdateQueueRequest], gct_queue.Queue]: 

3635 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3636 # In C++ this would require a dynamic_cast 

3637 return self._UpdateQueue(self._session, self._host, self._interceptor) # type: ignore 

3638 

3639 @property 

3640 def get_location(self): 

3641 return self._GetLocation(self._session, self._host, self._interceptor) # type: ignore 

3642 

3643 class _GetLocation( 

3644 _BaseCloudTasksRestTransport._BaseGetLocation, CloudTasksRestStub 

3645 ): 

3646 def __hash__(self): 

3647 return hash("CloudTasksRestTransport.GetLocation") 

3648 

3649 @staticmethod 

3650 def _get_response( 

3651 host, 

3652 metadata, 

3653 query_params, 

3654 session, 

3655 timeout, 

3656 transcoded_request, 

3657 body=None, 

3658 ): 

3659 uri = transcoded_request["uri"] 

3660 method = transcoded_request["method"] 

3661 headers = dict(metadata) 

3662 headers["Content-Type"] = "application/json" 

3663 response = getattr(session, method)( 

3664 "{host}{uri}".format(host=host, uri=uri), 

3665 timeout=timeout, 

3666 headers=headers, 

3667 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3668 ) 

3669 return response 

3670 

3671 def __call__( 

3672 self, 

3673 request: locations_pb2.GetLocationRequest, 

3674 *, 

3675 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3676 timeout: Optional[float] = None, 

3677 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3678 ) -> locations_pb2.Location: 

3679 r"""Call the get location method over HTTP. 

3680 

3681 Args: 

3682 request (locations_pb2.GetLocationRequest): 

3683 The request object for GetLocation method. 

3684 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3685 should be retried. 

3686 timeout (float): The timeout for this request. 

3687 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3688 sent along with the request as metadata. Normally, each value must be of type `str`, 

3689 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3690 be of type `bytes`. 

3691 

3692 Returns: 

3693 locations_pb2.Location: Response from GetLocation method. 

3694 """ 

3695 

3696 http_options = ( 

3697 _BaseCloudTasksRestTransport._BaseGetLocation._get_http_options() 

3698 ) 

3699 

3700 request, metadata = self._interceptor.pre_get_location(request, metadata) 

3701 transcoded_request = ( 

3702 _BaseCloudTasksRestTransport._BaseGetLocation._get_transcoded_request( 

3703 http_options, request 

3704 ) 

3705 ) 

3706 

3707 # Jsonify the query params 

3708 query_params = ( 

3709 _BaseCloudTasksRestTransport._BaseGetLocation._get_query_params_json( 

3710 transcoded_request 

3711 ) 

3712 ) 

3713 

3714 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3715 logging.DEBUG 

3716 ): # pragma: NO COVER 

3717 request_url = "{host}{uri}".format( 

3718 host=self._host, uri=transcoded_request["uri"] 

3719 ) 

3720 method = transcoded_request["method"] 

3721 try: 

3722 request_payload = json_format.MessageToJson(request) 

3723 except: 

3724 request_payload = None 

3725 http_request = { 

3726 "payload": request_payload, 

3727 "requestMethod": method, 

3728 "requestUrl": request_url, 

3729 "headers": dict(metadata), 

3730 } 

3731 _LOGGER.debug( 

3732 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.GetLocation", 

3733 extra={ 

3734 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3735 "rpcName": "GetLocation", 

3736 "httpRequest": http_request, 

3737 "metadata": http_request["headers"], 

3738 }, 

3739 ) 

3740 

3741 # Send the request 

3742 response = CloudTasksRestTransport._GetLocation._get_response( 

3743 self._host, 

3744 metadata, 

3745 query_params, 

3746 self._session, 

3747 timeout, 

3748 transcoded_request, 

3749 ) 

3750 

3751 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3752 # subclass. 

3753 if response.status_code >= 400: 

3754 raise core_exceptions.from_http_response(response) 

3755 

3756 content = response.content.decode("utf-8") 

3757 resp = locations_pb2.Location() 

3758 resp = json_format.Parse(content, resp) 

3759 resp = self._interceptor.post_get_location(resp) 

3760 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3761 logging.DEBUG 

3762 ): # pragma: NO COVER 

3763 try: 

3764 response_payload = json_format.MessageToJson(resp) 

3765 except: 

3766 response_payload = None 

3767 http_response = { 

3768 "payload": response_payload, 

3769 "headers": dict(response.headers), 

3770 "status": response.status_code, 

3771 } 

3772 _LOGGER.debug( 

3773 "Received response for google.cloud.tasks_v2.CloudTasksAsyncClient.GetLocation", 

3774 extra={ 

3775 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3776 "rpcName": "GetLocation", 

3777 "httpResponse": http_response, 

3778 "metadata": http_response["headers"], 

3779 }, 

3780 ) 

3781 return resp 

3782 

3783 @property 

3784 def list_locations(self): 

3785 return self._ListLocations(self._session, self._host, self._interceptor) # type: ignore 

3786 

3787 class _ListLocations( 

3788 _BaseCloudTasksRestTransport._BaseListLocations, CloudTasksRestStub 

3789 ): 

3790 def __hash__(self): 

3791 return hash("CloudTasksRestTransport.ListLocations") 

3792 

3793 @staticmethod 

3794 def _get_response( 

3795 host, 

3796 metadata, 

3797 query_params, 

3798 session, 

3799 timeout, 

3800 transcoded_request, 

3801 body=None, 

3802 ): 

3803 uri = transcoded_request["uri"] 

3804 method = transcoded_request["method"] 

3805 headers = dict(metadata) 

3806 headers["Content-Type"] = "application/json" 

3807 response = getattr(session, method)( 

3808 "{host}{uri}".format(host=host, uri=uri), 

3809 timeout=timeout, 

3810 headers=headers, 

3811 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3812 ) 

3813 return response 

3814 

3815 def __call__( 

3816 self, 

3817 request: locations_pb2.ListLocationsRequest, 

3818 *, 

3819 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3820 timeout: Optional[float] = None, 

3821 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3822 ) -> locations_pb2.ListLocationsResponse: 

3823 r"""Call the list locations method over HTTP. 

3824 

3825 Args: 

3826 request (locations_pb2.ListLocationsRequest): 

3827 The request object for ListLocations method. 

3828 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3829 should be retried. 

3830 timeout (float): The timeout for this request. 

3831 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3832 sent along with the request as metadata. Normally, each value must be of type `str`, 

3833 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3834 be of type `bytes`. 

3835 

3836 Returns: 

3837 locations_pb2.ListLocationsResponse: Response from ListLocations method. 

3838 """ 

3839 

3840 http_options = ( 

3841 _BaseCloudTasksRestTransport._BaseListLocations._get_http_options() 

3842 ) 

3843 

3844 request, metadata = self._interceptor.pre_list_locations(request, metadata) 

3845 transcoded_request = ( 

3846 _BaseCloudTasksRestTransport._BaseListLocations._get_transcoded_request( 

3847 http_options, request 

3848 ) 

3849 ) 

3850 

3851 # Jsonify the query params 

3852 query_params = ( 

3853 _BaseCloudTasksRestTransport._BaseListLocations._get_query_params_json( 

3854 transcoded_request 

3855 ) 

3856 ) 

3857 

3858 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3859 logging.DEBUG 

3860 ): # pragma: NO COVER 

3861 request_url = "{host}{uri}".format( 

3862 host=self._host, uri=transcoded_request["uri"] 

3863 ) 

3864 method = transcoded_request["method"] 

3865 try: 

3866 request_payload = json_format.MessageToJson(request) 

3867 except: 

3868 request_payload = None 

3869 http_request = { 

3870 "payload": request_payload, 

3871 "requestMethod": method, 

3872 "requestUrl": request_url, 

3873 "headers": dict(metadata), 

3874 } 

3875 _LOGGER.debug( 

3876 f"Sending request for google.cloud.tasks_v2.CloudTasksClient.ListLocations", 

3877 extra={ 

3878 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3879 "rpcName": "ListLocations", 

3880 "httpRequest": http_request, 

3881 "metadata": http_request["headers"], 

3882 }, 

3883 ) 

3884 

3885 # Send the request 

3886 response = CloudTasksRestTransport._ListLocations._get_response( 

3887 self._host, 

3888 metadata, 

3889 query_params, 

3890 self._session, 

3891 timeout, 

3892 transcoded_request, 

3893 ) 

3894 

3895 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3896 # subclass. 

3897 if response.status_code >= 400: 

3898 raise core_exceptions.from_http_response(response) 

3899 

3900 content = response.content.decode("utf-8") 

3901 resp = locations_pb2.ListLocationsResponse() 

3902 resp = json_format.Parse(content, resp) 

3903 resp = self._interceptor.post_list_locations(resp) 

3904 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3905 logging.DEBUG 

3906 ): # pragma: NO COVER 

3907 try: 

3908 response_payload = json_format.MessageToJson(resp) 

3909 except: 

3910 response_payload = None 

3911 http_response = { 

3912 "payload": response_payload, 

3913 "headers": dict(response.headers), 

3914 "status": response.status_code, 

3915 } 

3916 _LOGGER.debug( 

3917 "Received response for google.cloud.tasks_v2.CloudTasksAsyncClient.ListLocations", 

3918 extra={ 

3919 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

3920 "rpcName": "ListLocations", 

3921 "httpResponse": http_response, 

3922 "metadata": http_response["headers"], 

3923 }, 

3924 ) 

3925 return resp 

3926 

3927 @property 

3928 def kind(self) -> str: 

3929 return "rest" 

3930 

3931 def close(self): 

3932 self._session.close() 

3933 

3934 

3935__all__ = ("CloudTasksRestTransport",)